To write a program to find the LU Decomposition of a matrix.
- Hardware โ PCs
- Anaconda โ Python 3.7 Installation / Moodle-Code Runner
1.Import the numpy module to use the built-in functions for calculation.
2.From scipy.linalg module import the lu funtion.
3.Get inputs from the user and assign the values in np.array().
4.Using the lu() function,we can find the L and U matrix.
5.Print the obtained values.
6.End the program.
(i) To find the L and U matrix
Program to find the L and U matrix.
Developed by: K.SANTHANA LAKSHMI
RegisterNumber: 212222240091
import numpy as np
from scipy.linalg import lu
a=eval(input())
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: K.SANTHANA LAKSHMI
RegisterNumber: 212222240091
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)
*/
(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.