Write a computer program to perform Jacobi iteration for the system of equations
ID: 3649196 • Letter: W
Question
Write a computer program to perform Jacobi iteration for the system ofequations given using MATLAB PROGRAMMING. 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.
Now, I need the A matrix and the b to be in the program and not just something that you type in later on and then apply a function. I have already written a Gauss Seidel Code but for some reason I am struggling with the Jacobi one with the exact same matrix.
The A Matrix is [-1,2,1;-1,4,1;-2,4,3] and the b matrix is [1;2;3]. I need Ax = b using the Jacobi Method
Explanation / Answer
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
Related 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.