**Using Matlab** Make the program for Jacobi iteration method and compare solutions obtaned by two algorithms, Jacobi-iteration...

Free

50.1K

Verified Solution

Question

Advance Math

**Using Matlab**

  • Make the program for Jacobi iteration method and compare solutionsobtaned by two algorithms, Jacobi-iteration method and Gaussianelimination.

Answer & Explanation Solved by verified expert
4.3 Ratings (682 Votes)

%%% Gauss Ellimination

function [ Ahat, x]=GaussElim( A,b)
if det(A)==0
disp('Unique solution is not possible : ');
else
[r c]=size(A);
for n=1:r
Ahat(n,:)=[A(n,:) b(n)];
end
for i=1:r
k=0;
for j=1:c
  
if (i==j)
Ahat(i,:)=Ahat(i,:)/Ahat(i,j);
k=1;
end
if ( j > i)
if (k==1)
Ahat(j,:)=Ahat(j,:)-Ahat(j,i)*Ahat(i,:);
end
end
  
end
end
x(1:r)=0;
x(r)=Ahat(end,end);
for i=r-1:-1:1
for j=c:-1:1
if (j > i)
x(i)=x(i)-x(j)*Ahat(i,j);
end
end
x(i)=x(i)+Ahat(i,end);
end

end
end

%%% Jacobi iteration

function [ x1]= jacobi ( A, b);
tol=10^(-5);
disp('Gauss jacobi method');
[r,c]=size(A);
for n=1:r
for k=1:c
if (n==k)
D(n,k)=A(n,k);
else
R(n,k)=A(n,k);
end
end
end

x(:,1)=[0 0 0]'; %%%Initial guess
disp('Solution at each iteration ');
% fprintf(' d p g ');
for n=1:40
x(:,n+1)=inv(D)*(b-R*x(:,n));
err=x(:,n+1)-x(:,n);
if (norm(err,Inf) < tol)
%   
break;
end
fprintf('iteration %d %f %f %f ',n,x(1,n),x(2,n), x(3,n));
  
  
end
x1=x(:,end);
end


Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students