Software tutorial/Matrix operations
Jump to navigation
Jump to search
Matrix operations
In this section we will see how to calculate the LU decomposition, matrix inverse, norms and condition number of a matrix.
Let A = \(\left(\begin{array}{cccc} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{array} \right)\) and let B = \(\left(\begin{array}{cccc} 4 & 0 & 1 \\ 0 & 6 & 2 \\ 3.2 & 7 & 4 \end{array} \right)\)
MATLAB | Python |
---|---|
A = eye(3);
B = [4, 0, 1; 0, 6, 2; 3.2, 7, 4];
% LU decomposition of B
[L,U,P] = lu(B)
L =
1.0000 0 0
0.8000 1.0000 0
0 0.8571 1.0000
U =
4.0000 0 1.0000
0 7.0000 3.2000
0 0 -0.7429
P =
1 0 0
0 0 1
0 1 0
|
import numpy as np
from scipy.linalg import *
A = np.eye(3)
B = np.array([[4, 0, 1],[0, 6, 2],[3.2, 7, 4]])
LU, P = lu_factor(B)
LU
array([[ 4. , 0. , 1. ],
[ 0.8 , 7. , 3.2 ],
[ 0. , 0.85714286, -0.74285714]])
P
array([0, 2, 2])
|