Question: Q2. (LU decomposition) Write a python code for solving a system of linear equations by LU decomposition. Written in matrix form, a system of linear

 Q2. (LU decomposition) Write a python code for solving a system

Q2. (LU decomposition) Write a python code for solving a system of linear equations by LU decomposition. Written in matrix form, a system of linear equations is expressed as Ax = b. The pivoted LU decomposition on A gives A = PLU. Then, the equations become PLUX b. We can firstly solve Lz = PT b for z by the forward substitution, and finally solve Ux = z for x by the backward substitution. 1. Define a function plu_decomposition(A) which takes in A, does pivoted LU decomposition by scipy.linalg.lu() , and returns the permutation matrix P, the lower triangular matrix L and the upper triangular matrix U. 2. Define a function forward_subs(L, Pb) which takes in L and Pb, does forward substitution, and returns the result after forward substitution z. 3. Define a function solve_by_lu_decomp (A, b) which takes in A and b, does LU decomposition by calling plu_decomposition(A) defined in Q2.1, print out the result of LU decomposition (i.e., P, L and U), does forward substitution by calling forward_subs() defined in Q2.2 on L and PTb and returns z, does backward_substitution by calling backward_subs() defined in Q1.2 on U and z and returns the solution x. 4. Apply the function solve_by_lu_decomp (A, b) defined in Q2.3 to solve the following equations: 2 -3 -1 7 1 31 5. Solve the same equations in Q2.4 by scipy.linalg. solve() directly. ) Q2. (LU decomposition) Write a python code for solving a system of linear equations by LU decomposition. Written in matrix form, a system of linear equations is expressed as Ax = b. The pivoted LU decomposition on A gives A = PLU. Then, the equations become PLUX b. We can firstly solve Lz = PT b for z by the forward substitution, and finally solve Ux = z for x by the backward substitution. 1. Define a function plu_decomposition(A) which takes in A, does pivoted LU decomposition by scipy.linalg.lu() , and returns the permutation matrix P, the lower triangular matrix L and the upper triangular matrix U. 2. Define a function forward_subs(L, Pb) which takes in L and Pb, does forward substitution, and returns the result after forward substitution z. 3. Define a function solve_by_lu_decomp (A, b) which takes in A and b, does LU decomposition by calling plu_decomposition(A) defined in Q2.1, print out the result of LU decomposition (i.e., P, L and U), does forward substitution by calling forward_subs() defined in Q2.2 on L and PTb and returns z, does backward_substitution by calling backward_subs() defined in Q1.2 on U and z and returns the solution x. 4. Apply the function solve_by_lu_decomp (A, b) defined in Q2.3 to solve the following equations: 2 -3 -1 7 1 31 5. Solve the same equations in Q2.4 by scipy.linalg. solve() directly. )

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!