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.
- import scipy using library linalg.
- Solve using scipy.linalg.lu(variable)
- Print the output.
(i) To find the L and U matrix
/*
'''Program to find L and U matrix using LU decomposition.
Developed by: S.M.Syed Mokthiyar
RegisterNumber: 22006227
'''
# To print L and U matrix
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 solve a matrix using LU decomposition.
Developed by: S.M.Syed Mokthiyar
RegisterNumber: 22006227
'''
# To print X matrix (solution to the equations)
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)
Thus the program to find the LU Decomposition of a matrix is written and verified using python programming.