 |
Matrix
decomposition
Matlab includes several functions for matrix decomposition
or factorization.
LU
decomposition: the name of the built-in function is 'lu'. To get the LU
factorization of a square matrix M,
type the command [L,U] =
lu(M).
Matlab returns a lower
triangular matrix L
and an upper triangular
matrix U
such that L*U = M.
Example:
Type
M = [2 3
4 5
3 2 6 1
2 3 1 7
9 8 0 2];
[l,u] = lu(M)
l*u
Matlab answer is:
l =
0.2222
1.0000
0.4583 1.0000
0.3333 -0.5455
1.0000
0
0.2222
1.0000
0
0
1.0000
0
0
0
u =
9.0000
8.0000
0 2.0000
0 1.2222
1.0000 6.5556
0
0 6.5455
3.9091
0
0
0 -3.7917
ans =
2.0000
3.0000
4.0000 5.0000
3.0000
2.0000
6.0000 1.0000
2.0000
3.0000
1.0000 7.0000
9.0000
8.0000
0 2.0000
QR
factorization: the name of the appropriate built-in
function for this purpose is 'qr'.
Typing the command [Q,R]
= qr(M) returns an orthogonal
matrix Q
and an upper triangular
matrix R
such that Q*R = M.
Example (assuming
the same matrix M as
above):
Type
[q,r] = qr(M)
q*r
and the fast Matlab answer is:
q =
-0.2020 0.6359
-0.4469 -0.5959
-0.3030 -0.4127
-0.8144 0.2731
-0.2020
0.6359
0.0027 0.7449
-0.9091 -0.1450
0.3702 -0.1241
r =
-9.8995 -9.0914
-2.8284 -4.5457
0 1.8295
0.7028 6.9274
0
0 -6.6713 -2.2896
0
0
0 2.2595
ans =
2.0000
3.0000
4.0000 5.0000
3.0000
2.0000
6.0000 1.0000
2.0000
3.0000
1.0000 7.0000
9.0000 8.0000
-0.0000 2.0000
Cholesky
decomposition: if you have a positive definite matrix A, you
can factorize the matrix with the built-in function 'chol'. The command R = chol(A);
produces an upper
triangular matrix R
such that R'*R = A for a positive definite A.
This is a brief reminder of what a positive definite matrix is:
An n by n matrix M
is positive definite if
xT Mx > 0 for all x
<> 0 and
xT Mx = 0 implies x
= 0
If matrix M
is symmetric, diagonally dominant, and has positive diagonal elements,
then M
is positive definite
If matrix M
is positive definite, then M
is diagonally dominant and has positive diagonal elements.
Example:
Type
M =
[1
1
1 1
1
2
3 4
1
3
6 10
1
4 10 20];
r = chol(M)
r'*r
and Matlab answer is:
r =
1
1
1 1
0
1
2 3
0
0
1 3
0
0
0 1
ans =
1
1
1 1
1
2
3 4
1
3
6 10
1
4 10 20
Singular
value decomposition (svd): the name of the built-in
function is svd.
Typing [U,S,V] = svd(M);
produces a diagonal matrix S,
of the same dimension as M
and with nonnegative diagonal elements in decreasing order, and unitary
matrices U
and V
so that M = U*S*V'.
Example
(considering the same matrix M as above):
Type
[u,s,v] = svd(M)
u*s*v'
and you get:
u =
-0.0602 -0.5304
0.7873 -0.3087
-0.2012 -0.6403
-0.1632 0.7231
-0.4581 -0.3918
-0.5321 -0.5946
-0.8638
0.3939
0.2654 0.1684
s =
26.3047
0
0
0
0
2.2034
0
0
0
0
0.4538
0
0
0
0 0.0380
v =
-0.0602 -0.5304
0.7873 -0.3087
-0.2012 -0.6403
-0.1632 0.7231
-0.4581 -0.3918
-0.5321 -0.5946
-0.8638
0.3939
0.2654 0.1684
ans =
1.0000
1.0000
1.0000 1.0000
1.0000
2.0000
3.0000 4.0000
1.0000
3.0000 6.0000 10.0000
1.0000 4.0000
10.0000 20.0000
From
'Matrix
Decomposition' to home
From
'Matrix
Decomposition' to 'Matlab Cookbook'


|
|