Cholesky() public static method

Cholesky Factorization of a Matrix.
Thrown when the requested operation is invalid. Thrown when a Singular Matrix error condition occurs.
public static Cholesky ( Matrix m ) : Matrix
m Matrix Input Matrix.
return Matrix
Example #1
0
        /// <summary>
        /// Solves Ax = b for x If A is not square or the system is overdetermined, this operation solves
        /// the linear least squares A.T * A x = A.T * b.
        /// </summary>
        /// <exception cref="InvalidOperationException">Thrown when the requested operation is invalid.</exception>
        /// <param name="A">Matrix A.</param>
        /// <param name="b">Vector b.</param>
        /// <returns>x.</returns>
        public static Vector operator /(Matrix A, Vector b)
        {
            if (A.Rows != b.Length)
            {
                throw new InvalidOperationException("Matrix row count does not match vector length!");
            }

            // LLS
            if (A.Rows != A.Cols)
            {
                Matrix C = A.T * A;
                Matrix L = C.Cholesky();
                Vector d = (A.T * b).ToVector();
                Vector z = Forward(L, d);
                Vector x = Backward(L.T, z);
                return(x);
            }
            // regular solve
            else
            {
                // need to be smarter here....
                return(((A ^ -1) * b).ToVector());
            }
        }
Example #2
0
 /// <summary>A Matrix extension method that choleskies the given m.</summary>
 /// <param name="m">Matrix.</param>
 /// <returns>A Matrix.</returns>
 public static Matrix Cholesky(this Matrix m)
 {
     return(Matrix.Cholesky(m));
 }