To write a program to find the LU Decomposition of a matrix.
- Hardware โ PCs
- Anaconda โ Python 3.7 Installation / Moodle-Code Runner
1. Define the package as scipy.linalg import lu.
2. Get input from user and print L and U matrix by 'print' .
3. Define a package as "from scipy.linalg import lu_factor, lu_solve" and create the variable as
'X' include the package in that variable.
4. print the variable 'X'
(i) To find the L and U matrix
# Program to find L and U matrix using LU decomposition.
# Developed by: Ganesh G.
# RegisterNumber: 212223230059
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: Ganesh G.
# RegisterNumber: 212223230059
import numpy as np
from scipy.linalg import lu
A = np.array(eval(input()))
B = np.array(eval(input()))
c = np.linalg.solve(A,B)
print(c)
(i) To find the L and U matrix
(ii) To find the LU Decomposition of a matrix
Thus the program to find the LU Decomposition of a matrix is written and verified using python programming.