当间隔增加时,MATLAB ode45 图会发生显着变化
MATLAB ode45 graph changes dramatically when interval increases
我正在使用 MATLAB 绘制洛伦兹系统的图形。基本上,我有
r=31;
x0 = [(-9+sqrt(81+40*r)).*10^-27 (2*r).*10^-27 0];
flor = @(t,s) [ -10*(s(1)-s(2)); r*s(1)-s(2)-s(1)*s(3);
-8/3*s(3)+s(1)*s(2)];
[t1,s1] = ode45(flor,(0:0.0005:30), x0);
subplot(2,1,1),
hold on
plot3(s1(:,1),s1(:,2),s1(:,3))
hold off
grid on
xlabel('x'),ylabel('y'),zlabel('z')
view(10,5)
axis tight
现在,当运行上面的时候,我得到了数字
但是,当我把ode45(flor,(0:0.0005:30), x0)
改成ode45(flor,(0:0.0005:31), x0)
(也就是我把30改成31),我得到下图
这是截然不同的!我唯一要改变的(除非我弄错了)是时间间隔增加 1。关于为什么会发生这种情况的任何线索?
罪魁祸首似乎是默认的最大时间步长。默认情况下,ode45
使用0.1*abs(diff(tspan))
,当模拟没有剧烈振荡时,可以提前使用。而且由于两次模拟的最终时间不同,最大值也会不同,时间行进中的微小变化会被混沌系统的时间演化放大。将两个模拟的最大值设置为相同的值会得到相同的结果。
这个代码
r=31;
x0 = [(-9+sqrt(81+40*r)).*10^-27 (2*r).*10^-27 0];
flor = @(t,s) [ -10*(s(1)-s(2)); r*s(1)-s(2)-s(1)*s(3);
-8/3*s(3)+s(1)*s(2)];
[t30,s30] = ode45(flor,0:0.0005:30, x0);
[t31,s31] = ode45(flor,0:0.0005:31, x0);
[t30p,s30p] = ode45(flor,0:0.0005:30, x0, odeset('MaxStep',3));
[t31p,s31p] = ode45(flor,0:0.0005:31, x0, odeset('MaxStep',3));
subplot(2,2,1);
plot3(s30(:,1),s30(:,2),s30(:,3));
grid on
xlabel('x'),ylabel('y'),zlabel('z')
view(10,5)
axis tight
title('30 Seconds: Default Maximum Time-Step');
subplot(2,2,2);
plot3(s31(t31<=30,1),s31(t31<=30,2),s31(t31<=30,3));
grid on
xlabel('x'),ylabel('y'),zlabel('z')
view(10,5)
axis tight
title('31 Seconds: Default Maximum Time-Step');
subplot(2,2,3);
plot3(s30p(:,1),s30p(:,2),s30p(:,3));
grid on
xlabel('x'),ylabel('y'),zlabel('z')
view(10,5)
axis tight
title('30 Seconds: Maximum Time-Step of 3');
subplot(2,2,4);
plot3(s31p(t31p<=30,1),s31p(t31p<=30,2),s31p(t31p<=30,3));
grid on
xlabel('x'),ylabel('y'),zlabel('z')
view(10,5)
axis tight
title('31 Seconds: Maximum Time-Step of 3');
生成此图
可以看出,匹配最大时间步长(底部的图表)会产生相同的输出。
我正在使用 MATLAB 绘制洛伦兹系统的图形。基本上,我有
r=31;
x0 = [(-9+sqrt(81+40*r)).*10^-27 (2*r).*10^-27 0];
flor = @(t,s) [ -10*(s(1)-s(2)); r*s(1)-s(2)-s(1)*s(3);
-8/3*s(3)+s(1)*s(2)];
[t1,s1] = ode45(flor,(0:0.0005:30), x0);
subplot(2,1,1),
hold on
plot3(s1(:,1),s1(:,2),s1(:,3))
hold off
grid on
xlabel('x'),ylabel('y'),zlabel('z')
view(10,5)
axis tight
现在,当运行上面的时候,我得到了数字
但是,当我把ode45(flor,(0:0.0005:30), x0)
改成ode45(flor,(0:0.0005:31), x0)
(也就是我把30改成31),我得到下图
这是截然不同的!我唯一要改变的(除非我弄错了)是时间间隔增加 1。关于为什么会发生这种情况的任何线索?
罪魁祸首似乎是默认的最大时间步长。默认情况下,ode45
使用0.1*abs(diff(tspan))
,当模拟没有剧烈振荡时,可以提前使用。而且由于两次模拟的最终时间不同,最大值也会不同,时间行进中的微小变化会被混沌系统的时间演化放大。将两个模拟的最大值设置为相同的值会得到相同的结果。
这个代码
r=31;
x0 = [(-9+sqrt(81+40*r)).*10^-27 (2*r).*10^-27 0];
flor = @(t,s) [ -10*(s(1)-s(2)); r*s(1)-s(2)-s(1)*s(3);
-8/3*s(3)+s(1)*s(2)];
[t30,s30] = ode45(flor,0:0.0005:30, x0);
[t31,s31] = ode45(flor,0:0.0005:31, x0);
[t30p,s30p] = ode45(flor,0:0.0005:30, x0, odeset('MaxStep',3));
[t31p,s31p] = ode45(flor,0:0.0005:31, x0, odeset('MaxStep',3));
subplot(2,2,1);
plot3(s30(:,1),s30(:,2),s30(:,3));
grid on
xlabel('x'),ylabel('y'),zlabel('z')
view(10,5)
axis tight
title('30 Seconds: Default Maximum Time-Step');
subplot(2,2,2);
plot3(s31(t31<=30,1),s31(t31<=30,2),s31(t31<=30,3));
grid on
xlabel('x'),ylabel('y'),zlabel('z')
view(10,5)
axis tight
title('31 Seconds: Default Maximum Time-Step');
subplot(2,2,3);
plot3(s30p(:,1),s30p(:,2),s30p(:,3));
grid on
xlabel('x'),ylabel('y'),zlabel('z')
view(10,5)
axis tight
title('30 Seconds: Maximum Time-Step of 3');
subplot(2,2,4);
plot3(s31p(t31p<=30,1),s31p(t31p<=30,2),s31p(t31p<=30,3));
grid on
xlabel('x'),ylabel('y'),zlabel('z')
view(10,5)
axis tight
title('31 Seconds: Maximum Time-Step of 3');
生成此图
可以看出,匹配最大时间步长(底部的图表)会产生相同的输出。