I'm solving a system Ax=b with Jacobi. I got it to run through once, but now I need a driver to run 20 iterations of each, while printing the infinity norm of ||t-x^i|| ,where x^i is generated from an initial guess of x0, to a table each iteration.
2 次查看(过去 30 天)
显示 更早的评论
function driver
A = [4 -1 -1 0;-1 4 0 -1;-1 0 4 -1;0 -1 -1 4]';
b = [10.5;-13;1;-1.5];
n = 4;
%% exact solution
t = [2;-3;.5;-1];
x0=[0; 0; 0; 0];
%% updated x vector for infinity norm
x=(1:n);
for i= 1:20
if i = 1
%% initiating jacobi with x0
x = x0;
else x=x(i);
end
Jacobi(A,b,x,n)
%% calculating the infinity norm each iteration
z=norm(t-x(i),inf);
end
end
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Model Verification 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!