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

I am able to solve using the Jacobi method but I cannot get my Gauss-Seidel meth

ID: 3699955 • Letter: I

Question

I am able to solve using the Jacobi method but I cannot get my Gauss-Seidel method to run correctly. When I try and run the Gauss-Siedel method I get stuck in an infinite loop.

Use (a) the Jacobi and (b) the Gauss-Seidel methods to solve the linear system Ax b to within 10 in the , norm, where the entries of A are: 2, when j= i and i = 1, 2, , 80, j-i 2 andi 3,4., 80, aij = j = i + 4 and i = 1, 2, . . . . 76. i-4 and i-5,6,....80. 0.25, when 0, otherwise, and those ofb areb,-? for each i =1,2, .,80.

Explanation / Answer

SAVE THE FOLLOWING CODE IN MATLAB AND GE THE RESULTS-

Part (A)-

clc

clear

close all;

format compact

%% Read or Input any square Matrix

A=[-6 2 1 2 1;

    3 8 -4 1 0;

    -1 1 4 10 1;

    3 -4 1 9 2;

    2 0 1 3 10];% coefficients matrix

C=[3;4;-2 ;12;1];% constants vector

n=length(C);

X=zeros(n,1);

Error_eval=ones(n,1);

%% Check if the matrix A is diagonally dominant

for i=1:n

   j=1:n;

   j(i)=[];

   B=abs(A(i,j));

   Check(i)=abs(A(i,i))-sum(B); % Is the diagonal value greater than the remaining row values combined?

   if Check(i)<0

       fprintf('The matrix is not strictly diagonally dominant at row %2i ',i)

   end

end

%% Start the Iterative method

iteration=0;

while max(Error_eval)>0.001

   iteration=iteration+1;

   Z=X; % save current values to calculate error later

   for i=1:n

       j=1:n; % define an array of the coefficients' elements

       j(i)=[]; % eliminate the unknow's coefficient from the remaining coefficients

       Xtemp=X; % copy the unknows to a new variable

       Xtemp(i)=[]; % eliminate the unknown under question from the set of values

       X(i)=(C(i)-sum(A(i,j)*Xtemp))/A(i,i);

   end

   Xsolution(:,iteration)=X;

   Error_eval=sqrt((X-Z).^2);

end

%% Display Results

GaussSeidelTable=[1:iteration;Xsolution]'

MaTrIx = [A X C]

Part (B)

function x1=jacobi2(a,b,x0,tol)

n=length(b);

for j=1:n

    x(j)=((b(j)-a(j,[1:j-1,j+1:n])*x0([1:j-1,j+1:n]))/a(j,j)); % the first iteration

end

x1=x';

k=1;

while norm(x1-x0,1)>tol

   for j=1:n

    x_ny(j)=((b(j)-a(j,[1:j-1,j+1:n])*x1([1:j-1,j+1:n]))/a(j,j));

   end

   x0=x1;

   x1=x_ny';

   k=k+1;

end

k

x=x1';