the Jacobi Iterative method(urgent)

hello , I have to Write a Matlab code to solve an n x n linear
system using the Jacobi Iterative method
I need this code to solve this problem
I wrote this code but it does not solve it correctly
A = [ 1 -1 2 -1 ;2 -2 3 -3;1 1 1 0;1 -1 4 3];
b = [-8; -20; -2; 4];
% error tolerance
tol =10^-3;
%initial guess:
x0 = zeros(4,1);
xnew=x0;
error=1;
while error>tol
xold=xnew;
for i=1:length(xnew)
off_diag = [1:i-1 i+1:length(xnew)];
xnew(i) = 1/A(i,i)*( b(i)-sum(A(i,off_diag)*xold(off_diag)) );
end
error=norm(xnew-xold)/norm(xnew);
end
x_jacobian=xnew
the answer must be like this
can anybody help me ( the deadline for this homework tomorrow)

6 件のコメント

Torsten
Torsten 2020 年 4 月 11 日
Take A and b from the exercise. The Jacobi method is not guaranteed to converge for arbitrary matrices.
Further, use norm(...,Inf) instead of norm.
Mahdi Almahuzi
Mahdi Almahuzi 2020 年 4 月 11 日
can anyone fix the code and send it please
Torsten
Torsten 2020 年 4 月 11 日
Wnat error do you get ?
Mahdi Almahuzi
Mahdi Almahuzi 2020 年 4 月 11 日
All the answers are not same (wrong). and i need to get same as the second pic
Torsten
Torsten 2020 年 4 月 11 日
Did you change A and b to the data of your exercise ?
Rik
Rik 2020 年 4 月 12 日
Your question is not urgent, the reason for that is explained here.
You can find guidelines for posting homework on this forum here.

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

タグ

質問済み:

2020 年 4 月 11 日

コメント済み:

Rik
2020 年 4 月 12 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by