예제 #1
0
        /**
         * <p>
         * The condition number of a matrix is used to measure the sensitivity of the linear
         * system <b>Ax=b</b>.  A value near one indicates that it is a well conditioned matrix.<br>
         * <br>
         * &kappa;<sub>p</sub> = ||A||<sub>p</sub>||A<sup>-1</sup>||<sub>p</sub>
         * </p>
         * <p>
         * If the matrix is not square then the condition of either A<sup>T</sup>A or AA<sup>T</sup> is computed.
         * <p>
         * @param A The matrix.
         * @param p p-norm
         * @return The condition number.
         */
        public static double conditionP(DMatrixRMaj A, double p)
        {
            if (p == 2)
            {
                return(conditionP2(A));
            }
            else if (A.numRows == A.numCols)
            {
                // square matrices are the typical case

                DMatrixRMaj A_inv = new DMatrixRMaj(A.numRows, A.numCols);

                if (!CommonOps_DDRM.invert(A, A_inv))
                {
                    throw new ArgumentException("A can't be inverted.");
                }

                return(normP(A, p) * normP(A_inv, p));
            }
            else
            {
                DMatrixRMaj pinv = new DMatrixRMaj(A.numCols, A.numRows);
                CommonOps_DDRM.pinv(A, pinv);

                return(normP(A, p) * normP(pinv, p));
            }
        }
예제 #2
0
        /// <summary>
        /// Computes the Moore-Penrose pseudo-inverse.
        /// </summary>
        public override SimpleMatrixD pseudoInverse()
        {
            SimpleMatrixD ret = createMatrix(mat.getNumCols(), mat.getNumRows());

            CommonOps_DDRM.pinv(mat, ret.getMatrix());

            return(ret);
        }