I can't find where my mistake is?
1 次查看(过去 30 天)
显示 更早的评论
A=[1 2 -1; 2 2 -1; 2 5 2];
b=[3; 4; 2];
x=[1; 1; 1];
tol=1e-7;
d=diag(A);
X=ones(3,1);
r=ones(3,1);
while norm(r)/norm(X)>=tol
X=(b-A*x)./d+x;
r=X-x;
x=X;
end
X
%X should be 1 4/9 -10/9
1 个评论
Bob Thompson
2019-2-21
It seems like your system is unstable, as X just perpetually increases in value. Without knowing the equation you're trying to code I don't know that I can help much more than that, but I would look at the X value equation some more.
回答(1 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!