Exemplo n.º 1
0
        /**
         * Q = I - gamma*u*u<sup>H</sup>
         */
        public static CMatrixRMaj householder(CMatrixRMaj u, float gamma)
        {
            int N = u.getDataLength() / 2;
            // u*u^H
            CMatrixRMaj uut = new CMatrixRMaj(N, N);

            VectorVectorMult_CDRM.outerProdH(u, u, uut);
            // foo = -gamma*u*u^H
            CommonOps_CDRM.elementMultiply(uut, -gamma, 0, uut);

            // I + foo
            for (int i = 0; i < N; i++)
            {
                int index = (i * uut.numCols + i) * 2;
                uut.data[index] = 1 + uut.data[index];
            }

            return(uut);
        }
Exemplo n.º 2
0
        /**
         * <p>
         * Unitary matrices have the following properties:<br><br>
         * Q*Q<sup>H</sup> = I
         * </p>
         * <p>
         * This is the complex equivalent of orthogonal matrix.
         * </p>
         * @param Q The matrix being tested. Not modified.
         * @param tol Tolerance.
         * @return True if it passes the test.
         */
        public static bool isUnitary(CMatrixRMaj Q, float tol)
        {
            if (Q.numRows < Q.numCols)
            {
                throw new ArgumentException("The number of rows must be more than or equal to the number of columns");
            }

            Complex_F32 prod = new Complex_F32();

            CMatrixRMaj[] u = CommonOps_CDRM.columnsToVector(Q, null);

            for (int i = 0; i < u.Length; i++)
            {
                CMatrixRMaj a = u[i];

                VectorVectorMult_CDRM.innerProdH(a, a, prod);

                if (Math.Abs(prod.real - 1) > tol)
                {
                    return(false);
                }
                if (Math.Abs(prod.imaginary) > tol)
                {
                    return(false);
                }

                for (int j = i + 1; j < u.Length; j++)
                {
                    VectorVectorMult_CDRM.innerProdH(a, u[j], prod);

                    if (!(prod.getMagnitude2() <= tol * tol))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }