Student[NumericalAnalysis]
MatrixDecomposition
factor a matrix
Calling Sequence
Parameters
Options
Description
Notes
Examples
MatrixDecomposition(A, opts)
A
-
Matrix; a square nxn matrix
opts
(optional) equation(s) of the form keyword=value, where keyword is one of digits, method, output, showsteps; the options for factoring the matrix A
digits = posint
The number of digits of precision in which the computations will be performed. By default, digits will be set to the environment variable Digits.
method = LU, PLU, LU[tridiagonal], PLU[scaled], LDU, LDLt, Cholesky
The type of decomposition to perform.
method = LU produces a factorization A=L·U, where L and U are lower and upper triangular, respectively. It is also possible to obtain the Gaussian transformation matrices generated by this decomposition.
method = PLU produces a factorization P·A=L·U, where L and U are lower and upper triangular, respectively, and P is the permutation matrix. It is also possible to obtain Gaussian transformation and permutation matrices generated by this decomposition.
method = LU[tridiagonal] produces the factorization A=L·U using the Crout factorization algorithm for tridiagonal matrices, where L and U are lower and upper triangular, respectively. Note that the matrix A must be tridiagonal; an error will be raised otherwise.
method = PLU[scaled] produces a factorization P·A=L·U, where L and U are lower and upper triangular, respectively, and P is the permutation matrix. This method uses scaled partial pivoting. It is also possible to obtain the Gaussian transformation and permutation matrices generated by this decomposition.
method = LDU produces the factorization A=L·D·U, where L is a unit lower-triangular matrix, D is a diagonal matrix, and U is the a unit upper-triangular matrix.
method = LDLt produces, for a symmetric real matrix A (Hermitian complex matrix A) the factorization A=L·D·Lt, where L is a unit lower-triangular matrix, D is a diagonal matrix, and Lt is the transpose (Hermitian, respectively) of L. Note that A must be symmetric (Hermitian, respectively); an error will be raised otherwise.
method = Cholesky produces, for a positive definite matrix A, the factorization A=R·Rt, where R is lower triangular and Rt is the transpose R. Note that A must be positive definite; an error will be raised otherwise.
By default, method = PLU. See the output option below for a description of the possible return value(s) for each method.
output = list
The return value for the function. L represents the lower-triangular matrix, U represents the upper-triangular matrix and D represents the diagonal matrix.
If method = LU then output can be one or more of L, U, Mmatrices, where output = Mmatrices returns a list of Gaussian transformation matrices. By default, output = [L, U].
If method = PLU then output can be one or more of P, L, U, Mmatrices, Ematrices, where output = Mmatrices returns a list of Gaussian transformation matrices and output = Ematrices returns a list of permutation matrices. By default, output = [P, L, U].
If method = LU[tridiagonal] then output can be one or more of L, U. By default, output = [L, U].
If method = PLU[scaled] then output can be one or more of P, L, U, Mmatrices, Ematrices, where output = Mmatrices returns a list of Gaussian transformation matrices and output = Ematrices returns a list of permutation matrices. By default, output = [P, L, U].
If method = LDU then output can be one or more of L, D, U. By default, output = [L, D, U].
If method = LDLt then output can be one or more of L, D, Lt, where output = Lt returns the unit upper-triangular matrix. By default, output = [L, D, Lt].
If method = Cholesky then output can be one or more of R, Rt, where output = R returns the lower-triangular matrix and output = Rt returns the transpose of the lower-triangular matrix. By default, output = [R, Rt].
showsteps = true or false
Whether to print helpful statements into the interface as the command executes. This option is only available when output = LU, PLU or PLU[scaled]. By default, showsteps = false.
Matrix decomposition is used to reduce the general linear system A.x=b to more manageable triangular systems.
The MatrixDecomposition command can perform the following decompositions: LU, PLU, LU Tridiagonal, PLU Scaled, LDU, LDLt and Cholesky.
Matrix decomposition is also sometimes referred to as matrix factorization. The terms are interchangeable.
When the method is set to either LU or LDU, this procedure operates symbolically; that is, the inputs are not automatically evaluated to floating-point quantities, and computations proceed symbolically and exactly whenever possible. To obtain floating-point results, it is necessary to supply floating-point inputs.
Otherwise, this procedure operates numerically; that is, if the inputs are not already numeric, they are first evaluated to floating-point quantities before computations proceed. The outputs will be numeric as well. Note that exact rationals are considered numeric and are preserved whenever possible throughout the computation; therefore, one must specify floating-point inputs instead of exact rationals to obtain floating-point outputs.
with⁡Student:-NumericalAnalysis:
A≔Matrix⁡1.3,4.5,7.2,4.3,5.6,8.7,7.0,8.4,10.1
A≔1.34.57.24.35.68.77.08.410.1
Try an LU decomposition
L,U≔MatrixDecomposition⁡A,method=LU,output=L,U
L,U≔1003.307692308105.3846153851.7050538511,1.34.57.20−9.28461539−15.1153846200−2.89668601
M≔MatrixDecomposition⁡A,method=LU,output=Mmatrices
M≔100−3.30769230810−5.38461538501,1000100−1.7050538511
Check that M2·M1·A=U
M2·M1·A−U
0.0.0.−4.00000033096148×10−104.00000033096148×10−92.40000019857689×10−91.82021508976504×10−10−1.35468471995637×10−8−1.04149577850876×10−8
A≔Matrix⁡3.32,1.43,2.02,9.93,2.43,1.54,2.54,1.53,6.54,1.21,1.04,8.54,−3.44,0.43,2.43,1.99
A≔3.321.432.029.932.431.542.541.536.541.211.048.54−3.440.432.431.99
Try a PLU decomposition
P,L,U≔MatrixDecomposition⁡A,method=PLU
P,L,U≔0010010000011000,10000.3715596330100−0.52599388380.9780264465100.50764525990.7481104427−0.13673442321,6.541.211.048.5401.0904128442.153577982−1.643119266000.8707774188.0890018650007.929989165
P
0010010000011000
L
10000.3715596330100−0.52599388380.9780264465100.50764525990.7481104427−0.13673442321
U
6.541.211.048.5401.0904128442.153577982−1.643119266000.8707774188.0890018650007.929989165
Perform a Cholesky decomposition
A≔Matrix⁡2,−1,0,−1,2,−1,0,−1,2
A≔2−10−12−10−12
First check that A is positive definite
IsMatrixShape⁡A,positivedefinite
true
G,Gt≔MatrixDecomposition⁡A,method=Cholesky
G,Gt≔200−226200−632⁢33,2−220062−63002⁢33
See Also
Student[LinearAlgebra]
Student[NumericalAnalysis][ComputationOverview]
Student[NumericalAnalysis][MatrixDecompositionTutor]
Download Help Document