In: Computer Science
Implement the recursive LU factorization algorithm in Python. Use plenty of
comments to explain your code. While you are coding, it is helpful to break up your code into sub-functions and test the sub-functions as you go along.
Suppose we are given a matrix A , we will compute L ans U in A=LU. We have to use recursive approach , so your recursive function will take original matrix as parameter and slice it into sub matrices and perform some operations.
We are given a n×n matrix , LU factorization will be written as-
Base case for our recursive function will be -
If Akk =0 then we will can not divide the matrix anymore.
Python code-
Let us create a function lu_fact(A) this takes A matrix as parameter and return return two matrices L and U.
Here L is the lower triangular matrix with 1 on diagonal and U is upper triangular matrix, the shape of L and U will be same as shape of A.
We will use the formula A=LU
This will return two matrices L and U.