To write a program to find the LU Decomposition of a matrix.
- Hardware โ PCs
- Anaconda โ Python 3.7 Installation / Moodle-Code Runner
- TO FIND L AND U MATRICES WITH LU DEOMPOSITION
get the matrix from the user.
using "from scipy.linalg import lu"to import scipy (LU) module.
using "L,U=LU(a)" we can get the matrix of L and U.
print the result matrices (L and U) matrices.
get the matrix from the user.
using "from scipy.linalg import lu_actor,lu_solve" to import scipy module for factorisation and solving X.
using "lu,piv=lu_factor(a)"
print the ouput(x matrix)
ed the program.
(i) To find the L and U matrix
/*
Program to find the L and U matrix.
Developed by: mohammed faizal
RegisterNumber: 22003412
*/
import numpy as np
from scipy.linalg import lu
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 find the LU Decomposition of a matrix.
Developed by: mohammed faizal
RegisterNumber: 22003412
*/
import numpy as mp
from scipy.linalg import lu_factor,lu_solve
A = np.array(eval(input())
B = np.array(eval(input())
lu,pivot = lu_factor(A )
x = lu_solve(lu,pivot),B)
print(x)
Thus the program to find the LU Decomposition of a matrix is written and verified using python programming.