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

Jacobi Iterative Method. Purpose: To solve Ax - b, given an initial approximatio

ID: 3916545 • Letter: J

Question

Jacobi Iterative Method. Purpose: To solve Ax - b, given an initial approximation x°. INPUT: The number of equations and unknowns n; the matrix (A) - ay, the entries b, the entries of XO = x(0), for l 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 1. Set k-1 Step 2. While ks N do Steps 3-6. Step 3. For i-1,...,n j-1 ?1 ji Step 4. If II x-XO lk TOL , then OUTPUT Xi, Step 5. Set k=k+1 Step 6. For i1,., setXO, -x , xn. STOP 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);