To write a program to find the LU Decomposition of a matrix.
- Hardware – PCs
- Anaconda – Python 3.7 Installation / Moodle-Code Runner
Import numpy library using import statement.
From scipy package import lu().
Get input from user and pass it as an array.
Get P, L, U matrix using lu()
Print L and U matrix
'''Program to find L and U matrix using LU decomposition.
Developed by: Keerthika N
RegisterNumber: 21000385
'''
# 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)
Thus the program to find the LU Decomposition of a matrix is written and verified using python programming.
To write a program to find the LU Decomposition of a matrix.
- Hardware – PCs
- Anaconda – Python 3.7 Installation / Moodle-Code Runner
Import numpy library using import statement.
From scipy package import lu_factor() and lu_solve().
Get two inputs from user and pass it as matrix array.
Find lu and pivot value of first matrix using lu_factor().
Find solution of the matrix by using lu_solve() by passing lu, pivot values as first argument and second matrix as second argument.
Print the solution.
'''Program to solve a matrix using LU decomposition.
Developed by: Keerthika N
RegisterNumber: 21000385
'''
# 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, 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.