我目前正在编写一个程序来显示松弛因子与使用Successive OverRelaxation Method
实现解决方案所需的迭代次数之间的关系这是关注的For循环:
for (w = 0:0.05:2)
T = -inv(D + w*L)*(w*U + (w -1) * D);
C = inv(D + w*L) * w *B ;
X = zeros(B);
for(i = 1:1:MaxIter)
X = T * X + C;
err = A * X - B;
if (abs(err) < abs(tol))
break
end
end
disp("Relaxation Factor = " + string(w) +" No. of iterations = " + string(i));
我希望绘制一个显示放松因子与否的关系的图。迭代次数(在w和i之间)。我该怎么办?
答案 0 :(得分:0)
按以下步骤进行操作
I=zeros(W)
for k = 1:size(W,"*")
w=W(k)
T = -inv(D + w*L)*(w*U + (w -1) * D);
C = inv(D + w*L) * w *B ;
X = zeros(B);
for(i = 1:1:MaxIter)
X = T * X + C;
err = A * X - B;
if (abs(err) < abs(tol))
I(k)=i
break
end
end
end
plot(W,I)