Write a computer program to perform Jacobi iteration for the system of equations
ID: 3649173 • Letter: W
Question
Write a computer program to perform Jacobi iteration for the system ofequations given in Problem 1. Use x1 = x2 = x3 = 0 as the starting solution
(initial guess). The program should prompt the user to input the convergence
criteria value and the maximum number of iterations allowed and should out-
put the solution along with the number of iterations it took for the solution to
converge to the user specied value.
I already did this for the Gauss Seidel Method, I just need the same problem switched to Jacobi Method.
clc
format compact
A = [-1,2,1;
-1,4,1;
-2,4,3];
b = [1;2;3];
n = length(b);
X = zeros(n,1);
p = input('Please enter the Criteria Value (ex:.001): ');
Criteria_value = ones(n,1);
iteration = 0;
while max(Criteria_value) > p;
iteration = iteration + 1;
L = X;
for i = 1:n
j = 1:n;
j(i) = [];
Xt = X;
Xt(i) = [];
X(i) = (b(i) - sum(A(i,j) * Xt)) / A(i,i);
end
Xf(:,iteration) = X;
Criteria_value = sqrt((X - L).^2);
end
GaussSeidelTable = [1:iteration;Xf]'
MaTrIx = [A X b]
Iterations = iteration
Explanation / Answer
unction x=gseidel(A,b,x,M,tau,lambda); % GSEIDEL Solves Ax=b using Gauss-Seidel iteration. % USAGE: % x=gseidel(A,b,x,M,tau,lambda); % % INPUTS: % A : nxn matrix % b : nxm matrix % [x] : nxm matrix of starting values. Default: b % [M] : maximum number of iterations % [tau] : convergence tolerence % [lambda] : over-relaxation parameter % % OUTPUT: % x : nxm matrix of approximate solutions to Ax=b if narginRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.