示例#1
0
        public static void invert(LinearSolverDense <CMatrixRMaj> solver, CMatrixRMaj A, CMatrixRMaj A_inv)
        {
            if (A.numRows != A_inv.numRows || A.numCols != A_inv.numCols)
            {
                throw new ArgumentException("A and A_inv must have the same dimensions");
            }

            CommonOps_CDRM.setIdentity(A_inv);

            solver.solve(A_inv, A_inv);
        }
示例#2
0
 public static CMatrixRMaj checkIdentity(CMatrixRMaj A, int numRows, int numCols)
 {
     if (A == null)
     {
         return(CommonOps_CDRM.identity(numRows, numCols));
     }
     else if (numRows != A.numRows || numCols != A.numCols)
     {
         throw new ArgumentException("Input is not " + numRows + " x " + numCols + " matrix");
     }
     else
     {
         CommonOps_CDRM.setIdentity(A);
     }
     return(A);
 }
        /**
         * <p>
         * To decompose the matrix 'A' it must have full rank.  'A' is a 'm' by 'n' matrix.
         * It requires about 2n*m<sup>2</sup>-2m<sup>2</sup>/3 flops.
         * </p>
         *
         * <p>
         * The matrix provided here can be of different
         * dimension than the one specified in the constructor.  It just has to be smaller than or equal
         * to it.
         * </p>
         */
        //@Override
        public bool decompose(CMatrixRMaj A)
        {
            setExpectedMaxSize(A.numRows, A.numCols);

            CommonOps_CDRM.transpose(A, QR);

            error = false;

            for (int j = 0; j < minLength; j++)
            {
                householder(j);
                updateA(j);
            }

            return(!error);
        }
示例#4
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]);
                }
            }
        }
示例#5
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);
        }
 //@Override
 public void minus(CMatrixRMaj A, CMatrixRMaj B, CMatrixRMaj output)
 {
     CommonOps_CDRM.subtract(A, B, output);
 }
 //@Override
 public void plus(CMatrixRMaj A, CMatrixRMaj B, CMatrixRMaj output)
 {
     CommonOps_CDRM.add(A, B, output);
 }
 //@Override
 public void mult(CMatrixRMaj A, CMatrixRMaj B, CMatrixRMaj output)
 {
     CommonOps_CDRM.mult(A, B, output);
 }
 //@Override
 public void transpose(CMatrixRMaj input, CMatrixRMaj output)
 {
     CommonOps_CDRM.transpose(input, output);
 }