To write a program to find the LU Decomposition of a matrix.
- Hardware โ PCs
- Anaconda โ Python 3.7 Installation / Moodle-Code Runner
1.Import the numpy module to use the built-in functions for calculation
2.Prepare the lists from each linear equations and assign in np.array()
3.Using the scipy.linalg and imort lu_fator and lu_solve we get the values
4.End the program
(i) To find the L and U matrix
/*
Program to find the L and U matrix.
Developed by: SUDHARSAN RAM M
RegisterNumber: 212222110048
*/
import numpy as np
from scipy.linalg import lu
a=np.array(eval(input()))
p,l,u=lu(a)
print(l)
print(u)
(ii) To find the LU Decomposition of a matrix
/*
Program to find the LU Decomposition of a matrix.
Developed by: SUDHARSAN RAM M
RegisterNumber: 212222110048
*/
import numpy as np
from scipy.linalg import lu_factor,lu_solve
a=np.array(eval(input()))
b=np.array(eval(input()))
lu,piv=lu_factor(a)
x=lu_solve((lu,piv),b)
print(x)
1
Thus the program to find the LU Decomposition of a matrix is written and verified using python programming.