Exemplo n.º 1
0
        /**
         * Computes the householder vector used in QR decomposition.
         *
         * u = x / max(x)
         * u(0) = u(0) + |u|
         * u = u / u(0)
         *
         * @param x Input vector.  Unmodified.
         * @return The found householder reflector vector
         */
        public static ZMatrixRMaj householderVector(ZMatrixRMaj x)
        {
            ZMatrixRMaj u = (ZMatrixRMaj)x.copy();

            double max = CommonOps_ZDRM.elementMaxAbs(u);

            CommonOps_ZDRM.elementDivide(u, max, 0, u);

            double      nx = NormOps_ZDRM.normF(u);
            Complex_F64 c  = new Complex_F64();

            u.get(0, 0, c);

            double realTau, imagTau;

            if (c.getMagnitude() == 0)
            {
                realTau = nx;
                imagTau = 0;
            }
            else
            {
                realTau = c.real / c.getMagnitude() * nx;
                imagTau = c.imaginary / c.getMagnitude() * nx;
            }

            u.set(0, 0, c.real + realTau, c.imaginary + imagTau);
            CommonOps_ZDRM.elementDivide(u, u.getReal(0, 0), u.getImag(0, 0), u);

            return(u);
        }
Exemplo n.º 2
0
        /**
         * Computes the N<sup>th</sup> root of a complex number.  There are
         * N distinct N<sup>th</sup> roots.
         *
         * @param a Complex number
         * @param N The root's magnitude
         * @param k Specifies which root.  0 &le; k &lt; N
         * @param result Computed root
         */
        public static void root(Complex_F64 a, int N, int k, Complex_F64 result)
        {
            double r     = a.getMagnitude();
            double theta = Math.Atan2(a.imaginary, a.real);

            r     = Math.Pow(r, 1.0 / N);
            theta = (theta + 2.0 * k * UtilEjml.PI) / N;

            result.real      = r * Math.Cos(theta);
            result.imaginary = r * Math.Sin(theta);
        }
Exemplo n.º 3
0
        /**
         * Computes the square root of the complex number.
         *
         * @param input Input complex number.
         * @param root Output. The square root of the input
         */
        public static void sqrt(Complex_F64 input, Complex_F64 root)
        {
            double r = input.getMagnitude();
            double a = input.real;

            root.real      = Math.Sqrt((r + a) / 2.0);
            root.imaginary = Math.Sqrt((r - a) / 2.0);
            if (input.imaginary < 0)
            {
                root.imaginary = -root.imaginary;
            }
        }
Exemplo n.º 4
0
 /**
  * <p>
  * Converts a complex number into polar notation.
  * </p>
  *
  * @param input Standard notation
  * @param output Polar notation
  */
 public static void convert(Complex_F64 input, ComplexPolar_F64 output)
 {
     output.r     = input.getMagnitude();
     output.theta = Math.Atan2(input.imaginary, input.real);
 }