/**
         * 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 CMatrixRMaj householderVector(CMatrixRMaj x)
        {
            CMatrixRMaj u = (CMatrixRMaj)x.copy();

            float max = CommonOps_CDRM.elementMaxAbs(u);

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

            float       nx = NormOps_CDRM.normF(u);
            Complex_F32 c  = new Complex_F32();

            u.get(0, 0, c);

            float 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_CDRM.elementDivide(u, u.getReal(0, 0), u.getImag(0, 0), u);

            return(u);
        }
Beispiel #2
0
        /**
         * <p>
         * Computes the Frobenius matrix norm:<br>
         * <br>
         * normF = Sqrt{  &sum;<sub>i=1:m</sub> &sum;<sub>j=1:n</sub> { a<sub>ij</sub><sup>2</sup>}   }
         * </p>
         * <p>
         * This is equivalent to the element wise p=2 norm.
         * </p>
         *
         * @param a The matrix whose norm is computed.  Not modified.
         * @return The norm's value.
         */
        public static float normF(CMatrixRMaj a)
        {
            float total = 0;

            float scale = CommonOps_CDRM.elementMaxAbs(a);

            if (scale == 0.0f)
            {
                return(0.0f);
            }

            int size = a.getDataLength();

            for (int i = 0; i < size; i += 2)
            {
                float real = a.data[i] / scale;
                float imag = a.data[i + 1] / scale;

                total += real * real + imag * imag;
            }

            return(scale * (float)Math.Sqrt(total));
        }