To write a program to find the LU Decomposition of a matrix.
- Hardware โ PCs
- Anaconda โ Python 3.7 Installation / Moodle-Code Runner
- Import the numpy module to use the built-in functions for calculation
- Prepare the lists from each linear equations and assign in np.array()
- Using the lu() function in scipy.linalg module, we can find the solutions.
- End the program
(i) To find the L and U matrix
/*
Program to find the L and U matrix.
Developed by: JAYAMANI R
RegisterNumber: 22008124
*/
import numpy as np
from scipy.linalg import lu
arr=eval(input())
A=np.array(arr)
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: JAYAMANI R
RegisterNumber: 22008124
*/
import numpy as np
from scipy.linalg import lu_factor,lu_solve
arr=eval(input())
A=np.array(arr)
B=eval(input())
res=lu_factor(A)
solution=lu_solve(res,B)
print(solution)
Thus the program to find the LU Decomposition of a matrix is written and verified using python programming.