示例#1
0
        /**
         * <p>
         * The condition p = 2 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>2</sub> = ||A||<sub>2</sub>||A<sup>-1</sup>||<sub>2</sub>
         * </p>
         * <p>
         * This is also known as the spectral condition number.
         * </p>
         *
         * @param A The matrix.
         * @return The condition number.
         */
        public static double conditionP2(DMatrixRMaj A)
        {
            SingularValueDecomposition_F64 <DMatrixRMaj> svd =
                DecompositionFactory_DDRM.svd(A.numRows, A.numCols, false, false, true);

            svd.decompose(A);

            double[] singularValues = svd.getSingularValues();

            int n = SingularOps_DDRM.rank(svd, UtilEjml.TEST_F64);

            if (n == 0)
            {
                return(0);
            }

            double smallest = double.MaxValue;
            double largest  = double.MinValue;

            foreach (double s in singularValues)
            {
                if (s < smallest)
                {
                    smallest = s;
                }
                if (s > largest)
                {
                    largest = s;
                }
            }

            return(largest / smallest);
        }
示例#2
0
        /**
         * Computes the nullity of a matrix using the specified tolerance.
         *
         * @param A Matrix whose rank is to be calculated.  Not modified.
         * @param threshold The numerical threshold used to determine a singular value.
         * @return The matrix's nullity.
         */
        public static int nullity(DMatrixRMaj A, double threshold)
        {
            SingularValueDecomposition_F64 <DMatrixRMaj> svd =
                DecompositionFactory_DDRM.svd(A.numRows, A.numCols, false, false, true);

            if (svd.inputModified())
            {
                A = (DMatrixRMaj)A.copy();
            }

            if (!svd.decompose(A))
            {
                throw new InvalidOperationException("Decomposition failed");
            }

            return(SingularOps_DDRM.nullity(svd, threshold));
        }