Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write this code using Matlab Gauss Siedel Iterative Method Purpose: To solve Ax-

ID: 3348359 • Letter: W

Question

Write this code using Matlab

Gauss Siedel Iterative Method Purpose: To solve Ax-b, given an initial approximation x INPUT: The number of equations and unknowns n ; the matrix (A), = aii , the entries b , the entries of XO -x0, for 1 s i,j s n; the error tolerance TOL; the maximum number of iterations N. OUTPUT: The approximate solution x ,...,x, or a message that the number of iterations was exceeded. Step I. Set k =1 Step 2. While k s N do Steps 3-6. Step 3. For 1,.. i-1 Set xb j-1 j-i+1 Step 4. Ifll x-XO lk TOL, then OUTPUT *,..,x. STOP Step 5. Set k -k+1 Step 6. For i=1 ,..,n set XO.-x, Step 7. OUTPUT('Max number of iterations exceeded'). STOP

Explanation / Answer

sample code for jacobi method is written below : please go through that and let me know if you have any queries.

%% jacobi method

%% solution of x in Ax= b using jacobi method

% Intialize 'A' 'b' and intial guess 'x'

A = [5 -2 3 0; -3 9 1 2 ; 2 -4 -7 1; 7 3 -5 4]

b = [2 -1 3 0.5]'

x = [0 0 0 0 ]'

n = size(x,1);

normVal = Inf;

%% tolerance for method

tol = 1e - 5; itr = 0;

%% algorithm

while normVal > tol

xold = x;

for i= 1: n

sigma = 0;

for j = 1 : n

if j-=i

sigma = sigma + A(i,j)*x(j);

end

end

x(i) = (1/A(i,j))*(b(i)-sigma);

end

itr = itr +1;

normVal = abs(xold - x);

end

fprint ('solution is : %f %f %f %f in %d' interation' , x, itr);