y1(k+1) = g1(y1(k));
y2(k+1) = g2(y2(k));
y3(k+1) = g3(y3(k));
y4(k+1) = g4(y4(k));
end
t=[1:iter_max+1];
plot(t,y1,'b.-',t,y2,'k.-',t,y3,'r.-',t,y4,'g.-','linewidth',1.5); legend('\phi_1','\phi_2','\phi_3','\phi_4');
______________________________
迭代的加速收敛方法
% 教材第 203 页例 7.8
clear all; close all;
syms x
g4 = (6*x^2 - 9*x +2)^(1/3);
dg4 = diff(g4,'x');
x0 = 3.5;
y4(1)=x0; y4n(1)=x0;
iter_max = 60;
for k = 1:iter_max
y4(k+1) = subs(g4,x,y4(k));
y4n_tmp = subs(g4,x,y4n(k))-subs(dg4,x,y4n(k))*y4n(k);
y4n(k+1) = y4n_tmp/(1-subs(dg4,x,y4n(k)));
end
t=[1:iter_max+1];
plot(t,y4,'g.-',t,y4n,'b.-','linewidth',1.5);
legend('old','new');
_______________________________
% Aitken 加速
clear all;
close all;
syms x
g4 = (6*x^2 - 9*x +2)^(1/3);
dg4 = diff(g4,'x');
x0 = 3.5;
y4(1)=x0; y4n(1)=x0; y5(1)=x0;
iter_max = 60;
for k = 1:iter_max
y4(k+1) = subs(g4,x,y4(k));
%
y4n_tmp = subs(g4,x,y4n(k))-subs(dg4,x,y4n(k))*y4n(k);