To write a program to find the LU Decomposition of a matrix.
- Hardware โ PCs
- Anaconda โ Python 3.7 Installation / Moodle-Code Runner
- import numpy as np
- from scipy package import lu
- get input from the user
- print result
(i) To find the L and U matrix
'''Program to find L and U matrix using LU decomposition.
Developed by: TILAK VELLACHI
RegisterNumber: 23009564
'''
from scipy.linalg import lu
import numpy as np
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 solve a matrix using LU decomposition.
Developed by: TILAK VELLACHI
RegisterNumber: 23009564
'''
from scipy.linalg import lu_factor,lu_solve
import numpy as np
arr=eval(input())
constant=eval(input())
A=np.array(arr)
B=np.array(constant)
result=lu_factor(A)
solution=lu_solve(result,B)
print(solution)
Thus the program to find the LU Decomposition of a matrix is written and verified using python programming.