Please help with the code for Gauss Seidel Method

조회 수: 7 (최근 30일)
alberto ortiz
alberto ortiz 2016년 11월 4일
댓글: alberto ortiz 2016년 11월 8일
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.
alberto ortiz
alberto ortiz 2016년 11월 8일
Thank you very much

댓글을 달려면 로그인하십시오.

추가 답변 (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
alberto ortiz
alberto ortiz 2016년 11월 4일
it has an error that code, thanks though
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