Please help with the code for Gauss Seidel Method

1 次查看(过去 30 天)
Please help with the code , I do not know what I am doing wrong. If you can please give me an advice. the first approximation should be x1=-0.2; x2=0.156 and x3=-.508. I have attached the code.
Please follow the format that I have already , because I will use it to do a bigger matrix 33 by 9

采纳的回答

Walter Roberson
Walter Roberson 2016-11-4
Your assigment to T should be within for loops where both sibscripts are changing
It is uncommon to call norm() passing in a single value. Also those subscripts imply the assigmnent to norm2 should be inside for loops.
  16 个评论
Walter Roberson
Walter Roberson 2016-11-8
You create T as length(b) by 6 in that last section, which is 249 x 6.

请先登录,再进行评论。

更多回答(1 个)

Torsten
Torsten 2016-11-4
编辑:Torsten 2016-11-4
L = [5 0 0; -3 9 0 ; 2 -1 -7];
U = [0 -2 3; 0 0 1 ; 0 0 0];
b = [-1 2 3];
epsilon = 1;
xold = [0 0 0];
while epsilon > 1e-5
xnew = L\(b-U*xold)
xnew
epsilon = norm((xnew-xold)./xold,1);
xold = xnew;
end
Best wishes
Torsten.
  2 个评论
Torsten
Torsten 2016-11-7
Try
L = [5 0 0; -3 9 0 ; 2 -1 -7];
U = [0 -2 3; 0 0 1 ; 0 0 0];
b = [-1;2;3];
epsilon = 1;
xold = [1;0;0];
while epsilon > 1e-5
xnew = L\(b-U*xold)
xnew
epsilon = norm((xnew-xold)./xold,1);
xold = xnew;
end
Best wishes
Torsten.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Assumptions 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by