Please code using python. Write your own function that implements the Gauss-Seid
ID: 3755933 • Letter: P
Question
Please code using python.
Write your own function that implements the Gauss-Seidel iteration method to solve Ax = b. Assume the matrix is diagonally dominant and no pivoting is required. Program the straight Gauss-Seidel method which updates the solution {x} using the most recent calculated values.
= 1/ ( xj ) , = 1, 2,……
The script file that you write is to export a function with an interface of:
def run(A,b):
This function will call your Gauss-Seidel solver and send it an arbitrary coefficient matrix A and right hand side vector b that the grader will supply. Use a starting vector of x = [1, 1, 1, …..] and iterate until the convergence criteria is met for all the x’s.
| ( ^(+1) ^) / (^(+1)) | <
Use eps = 0.0001 and print out the vector x and the number of iterations in the form:
Number of Iterations is < what you computed to convergence >
x is < the converged vector solution you computed >
Values should be printed outto 4significant digits of accuracy and displayed in scientific notation.
Explanation / Answer
//Gaus-seidel (Written by: Manas Sharma - University of Delhi) #include #include #include using namespace std; int main() { cout.precision(4); cout.setf(ios::fixed); int n,i,j,k,flag=0,count=0; coutn; //Input no. of equations double a[n][n+1]; //declare a 2d array for storing the elements of the augmented matrix double x[n]; //declare an array to store the values of variables double eps,y; coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.