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 user
- print result
/*
Program to find the LU Decomposition of a matrix.
Developed by: Janani R
RegisterNumber: 21500825
*/
import numpy as np
from scipy.linalg import lu
A=eval(input())
P,L,U=lu(A)
print(L)
print(U)
'''Program to solve a matrix using LU decomposition.
Developed by: Janani R
RegisterNumber: 21500825
'''
# To print X matrix (solution to the equations)
import numpy as np
from scipy.linalg import lu_factor, lu_solve
A=eval(input())
B=eval(input())
lu,piv=lu_factor(A)
x=lu_solve((lu, piv), B)
print(x)
Thus the program to find the LU Decomposition of a matrix is written and verified using python programming.