LU Decomposition. For an m-by-n matrix A with m >= n, the LU decomposition is an m-by-n unit lower triangular matrix L, an n-by-n upper triangular matrix U, and a permutation vector piv of length m so that A(piv,:) = L*U. If m is smaller than n, then L is m-by-m and U is m-by-n. The LU decompostion with pivoting always exists, even if the matrix is singular, so the constructor will never fail. The primary use of the LU decomposition is in the solution of square systems of simultaneous linear equations. This will fail if IsNonSingular() returns false.
Наследование: DirectSolver
Пример #1
0
 public MatrixValue Function(MatrixValue M)
 {
     var lu = new LUDecomposition(M);
     return lu.U;
 }
Пример #2
0
        /// <summary>
        /// Computes the determinant of the matrix.
        /// </summary>
        /// <returns>The value of the determinant.</returns>
        public ScalarValue Det()
        {
            if (DimensionX == DimensionY)
            {
                var n = DimensionX;

                if (n == 1)
                {
                    return this[1, 1];
                }
                else if (n == 2)
                {
                    return this[1, 1] * this[2, 2] - this[1, 2] * this[2, 1];
                }
                else if (n == 3)
                {
                    return this[1, 1] * (this[2, 2] * this[3, 3] - this[2, 3] * this[3, 2]) +
                            this[1, 2] * (this[2, 3] * this[3, 1] - this[2, 1] * this[3, 3]) +
                            this[1, 3] * (this[2, 1] * this[3, 2] - this[2, 2] * this[3, 1]);
                }
                else if (n == 4)
                {
                    //I guess that's right
                    return this[1, 1] * (this[2, 2] *
                                (this[3, 3] * this[4, 4] - this[3, 4] * this[4, 3]) + this[2, 3] *
                                    (this[3, 4] * this[4, 2] - this[3, 2] * this[4, 4]) + this[2, 4] *
                                        (this[3, 2] * this[4, 3] - this[3, 3] * this[4, 2])) -
                            this[1, 2] * (this[2, 1] *
                                (this[3, 3] * this[4, 4] - this[3, 4] * this[4, 3]) + this[2, 3] *
                                    (this[3, 4] * this[4, 1] - this[3, 1] * this[4, 4]) + this[2, 4] *
                                        (this[3, 1] * this[4, 3] - this[3, 3] * this[4, 1])) +
                            this[1, 3] * (this[2, 1] *
                                (this[3, 2] * this[4, 4] - this[3, 4] * this[4, 2]) + this[2, 2] *
                                    (this[3, 4] * this[4, 1] - this[3, 1] * this[4, 4]) + this[2, 4] *
                                        (this[3, 1] * this[4, 2] - this[3, 2] * this[4, 1])) -
                            this[1, 4] * (this[2, 1] *
                                (this[3, 2] * this[4, 3] - this[3, 3] * this[4, 2]) + this[2, 2] *
                                    (this[3, 3] * this[4, 1] - this[3, 1] * this[4, 3]) + this[2, 3] *
                                        (this[3, 1] * this[4, 2] - this[3, 2] * this[4, 1]));
                }

                var lu = new LUDecomposition(this);
                return lu.Determinant();
            }

            return ScalarValue.Zero;
        }
Пример #3
0
        /// <summary>
        /// Computes the inverse (if it exists).
        /// </summary>
        /// <returns>The inverse matrix.</returns>
        public MatrixValue Inverse()
        {
            var target = One(DimensionX);

            if (DimensionX < 24)
            {
                var lu = new YAMP.Numerics.LUDecomposition(this);
                return lu.Solve(target);
            }
            else if (IsSymmetric)
            {
                var cho = new YAMP.Numerics.CholeskyDecomposition(this);
                return cho.Solve(target);
            }

            var qr = YAMP.Numerics.QRDecomposition.Create(this);
            return qr.Solve(target);
        }
Пример #4
0
 public ArgumentsValue Function(MatrixValue M)
 {
     var lu = new LUDecomposition(M);
     return new ArgumentsValue(lu.L, lu.U, lu.Pivot);
 }