Question: import numpy as np #from copy import copy 1 ) Use the following forward substitution and back substitution functions def forward _ subs ( G

import numpy as np
#from copy import copy
1) Use the following forward substitution and back substitution functions
def forward_subs(G,b):
rows,cols = G.shape
x = np.zeros((rows,),dtype = float)
for i in range(rows):
Gx =0.0
for j in range(i):
Gx += G[i, j]* x[j]
x[i]=(b[i]- Gx)/ G[i, i]
return x
def back_subs(G,b):
rows,cols = G.shape
x = np.zeros((rows,),dtype = float)
for i in range(rows -1,-1,-1):
Gx =0.0
for j in range(i +1, cols):
Gx += G[i, j]* x[j]
x[i]=(b[i]- Gx)/ G[i, i]
return(x)
2) define a function
name : PLU_decomp
inputs : A (2D numpy array)
output : P (2d numpy array), L (2d numpy array), U (2d numpy array)
note 1 : the function should work for square matrices of any size
note 2 : use LU decomposition with pivoting
note 3 : PA = LU
def PLU_decomp(A):
# add code here
return(P,L,U)
3) define a function
name : solve_system_PLU
inputs : P (2d numpy array), L (2D numpy array), U (2D numpy array), b (1d numpy array)
output : x (1d numpy array)
note 1 : the function should work for square matrices of any size
note 2 : the function should solve the equation Ax=b where
PA=LU is the LU decomposition (with pivoting) of A
note 3 : call the forward subs and back subs functions to solve
4) def solve_system_PLU(P,L,U,b):
x = np.zeros(b.shape)
# add code here
return(x)

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 Programming Questions!