Question: Write a function that can solve a linear system, A x = b , using the Richardson iteration. Add this function to your HW 2
Write a function that can solve a linear system, using the Richardson iteration. Add this function to your
HWpy file and call it Richardson it
The function takes in a matrix a righthand side vector a scaling parameter an allowed tolerance, and a maximum iteration number and returns the approximate solution x Recall from lecture that the Richardson iteration can be defined as follows:
Axk
Where is the next approximate solution to the linear system. You will need to start with an initial guess for for now assume this is just the vector. Let the measure of error at the kth iteration be the norm of the vector Axk b Continue the Richardson iteration until either the error is below the input error tolerance or the maximum number of iterations are hit. The function should take the following inputs in this order:
numpy array : the matrix that defines the linear system
numpy array b: the right hand side vector of the linear system
float omega: the scaling parameter of the Richardson iteration by default this can be
float epsilon: the error tolerance
int max it: the maximum allowed number of iterations
And produce the following outputs in this order: numpy array : the approximate solution to the linear system
int it: the number of iterations taken to reach solution
float error : the calculated error in the last iteration
Hint: The Richardson iteration converges only if III so if you are
testing out your method on a matrix, be sul darr is property is satisfied. You can
check the norm of a matrix, A using numpy.linalg.normAord
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
