Esempio n. 1
0
        /**
         * <p>
         * Creates a reflector from the provided vector and gamma.<br>
         * <br>
         * Q = I - &gamma; u u<sup>H</sup><br>
         * </p>
         *
         * @param u A vector.  Not modified.
         * @param gamma To produce a reflector gamma needs to be equal to 2/||u||.
         * @return An orthogonal reflector.
         */
        public static ZMatrixRMaj createReflector(ZMatrixRMaj u, double gamma)
        {
            if (!MatrixFeatures_ZDRM.isVector(u))
            {
                throw new ArgumentException("u must be a vector");
            }

            ZMatrixRMaj Q = CommonOps_ZDRM.identity(u.NumElements);

            CommonOps_ZDRM.multAddTransB(-gamma, 0, u, u, Q);

            return(Q);
        }
Esempio n. 2
0
        /**
         * <p>
         * Creates a reflector from the provided vector.<br>
         * <br>
         * Q = I - &gamma; u u<sup>T</sup><br>
         * &gamma; = 2/||u||<sup>2</sup>
         * </p>
         *
         * @param u A vector. Not modified.
         * @return An orthogonal reflector.
         */
        public static ZMatrixRMaj createReflector(ZMatrixRMaj u)
        {
            if (!MatrixFeatures_ZDRM.isVector(u))
            {
                throw new ArgumentException("u must be a vector");
            }

            double norm  = NormOps_ZDRM.normF(u);
            double gamma = -2.0 / (norm * norm);

            ZMatrixRMaj Q = CommonOps_ZDRM.identity(u.NumElements);

            CommonOps_ZDRM.multAddTransB(gamma, 0, u, u, Q);

            return(Q);
        }
        /**
         * <p>
         * Extracts the diagonal elements 'src' write it to the 'dst' vector.  'dst'
         * can either be a row or column vector.
         * <p>
         *
         * @param src Matrix whose diagonal elements are being extracted. Not modified.
         * @param dst A vector the results will be written into. Modified.
         */
        public static void extractDiag(ZMatrixRMaj src, ZMatrixRMaj dst)
        {
            int N = Math.Min(src.numRows, src.numCols);

            // reshape if it's not the right size
            if (!MatrixFeatures_ZDRM.isVector(dst) || dst.numCols * dst.numCols != N)
            {
                dst.reshape(N, 1);
            }

            for (int i = 0; i < N; i++)
            {
                int index = src.getIndex(i, i);
                dst.data[i * 2]     = src.data[index];
                dst.data[i * 2 + 1] = src.data[index + 1];
            }
        }