Linear System
Linear System
Spring 2005
MATLAB EXAMPLES
Matrix Solution Methods
LU decomposition
Here is an example to use LU decomposition for 4X4 matrix A:
>> A=[7 3 -1 2;3 8 1 -4; -1 1 4 -1; 2 -4 -1 6] A= 7 3 -1 2 3 8 1 -4 -1 1 4 -1 2 -4 -1 6 >> [l u p]=lu(A) l= 1.0000 0 0 0 0.4286 1.0000 0 0 -0.1429 0.2128 1.0000 0 0.2857 -0.7234 0.0898 1.0000 u= 7.0000 3.0000 -1.0000 2.0000 0 6.7143 1.4286 -4.8571 0 0 3.5532 0.3191 0 0 0 1.8862 p= 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
Note: p is a permutation matrix corresponding to the pivoting strategy used. If the matrix is not diagonally dominant, p will not be an identity matrix.
Condition number
In MATLAB, Condition number is defined by:
( A ) = A A 1
To calculate condition number of matrix A by MATLAB built-in function:
>> cond(A) ans = 13.7473 Or by the definition, the product of 2-norm of A and inverse A: >> norm(A,2)*norm(inv(A),2) ans = 13.7473
0 0 0 6
12