/**
         * Performs QR decomposition on A
         *
         * @param A not modified.
         */
        //@Override
        public override bool setA(CMatrixRMaj A)
        {
            if (A.numRows < A.numCols)
            {
                throw new ArgumentException("Can't solve for wide systems.  More variables than equations.");
            }
            if (A.numRows > maxRows || A.numCols > maxCols)
            {
                setMaxSize(A.numRows, A.numCols);
            }

            R.reshape(A.numCols, A.numCols);
            a.reshape(A.numRows, 1);
            temp.reshape(A.numRows, 1);

            _setA(A);
            if (!decomposer.decompose(A))
            {
                return(false);
            }

            gammas = decomposer.getGammas();
            QR     = decomposer.getQR();
            decomposer.getR(R, true);
            return(true);
        }
示例#2
0
 /**
  * <p>Performs an "in-place" conjugate transpose.</p>
  *
  * @see #transpose(CMatrixRMaj)
  *
  * @param mat The matrix that is to be transposed. Modified.
  */
 public static void transposeConjugate(CMatrixRMaj mat)
 {
     if (mat.numCols == mat.numRows)
     {
         TransposeAlgs_CDRM.squareConjugate(mat);
     }
     else
     {
         CMatrixRMaj b = new CMatrixRMaj(mat.numCols, mat.numRows);
         transposeConjugate(mat, b);
         mat.reshape(b.numRows, b.numCols);
         mat.set(b);
     }
 }
示例#3
0
        public override /**/ double quality()
        {
            return(SpecializedOps_CDRM.qualityTriangular(R));
        }

        /**
         * Solves for X using the QR decomposition.
         *
         * @param B A matrix that is n by m.  Not modified.
         * @param X An n by m matrix where the solution is written to.  Modified.
         */
        //@Override
        public override void solve(CMatrixRMaj B, CMatrixRMaj X)
        {
            if (X.numRows != numCols)
            {
                throw new ArgumentException("Unexpected dimensions for X");
            }
            else if (B.numRows != numRows || B.numCols != X.numCols)
            {
                throw new ArgumentException("Unexpected dimensions for B");
            }

            int BnumCols = B.numCols;

            Y.reshape(numRows, 1);
            Z.reshape(numRows, 1);

            // solve each column one by one
            for (int colB = 0; colB < BnumCols; colB++)
            {
                // make a copy of this column in the vector
                for (int i = 0; i < numRows; i++)
                {
                    int indexB = B.getIndex(i, colB);
                    Y.data[i * 2]     = B.data[indexB];
                    Y.data[i * 2 + 1] = B.data[indexB + 1];
                }

                // Solve Qa=b
                // a = Q'b
                CommonOps_CDRM.mult(Qt, Y, Z);

                // solve for Rx = b using the standard upper triangular solver
                TriangularSolver_CDRM.solveU(R.data, Z.data, numCols);

                // save the results
                for (int i = 0; i < numCols; i++)
                {
                    X.set(i, colB, Z.data[i * 2], Z.data[i * 2 + 1]);
                }
            }
        }
示例#4
0
        /**
         * Performs QR decomposition on A
         *
         * @param A not modified.
         */
        //@Override
        public override bool setA(CMatrixRMaj A)
        {
            if (A.numRows > maxRows || A.numCols > maxCols)
            {
                setMaxSize(A.numRows, A.numCols);
            }

            _setA(A);
            if (!decomposer.decompose(A))
            {
                return(false);
            }

            Q.reshape(numRows, numRows);
            R.reshape(numRows, numCols);
            decomposer.getQ(Q, false);
            decomposer.getR(R, false);
            CommonOps_CDRM.transposeConjugate(Q, Qt);

            return(true);
        }