求解微分方程需要大量时间

solution of differential equation takes huge time

在发布实际代码之前,让我向您展示一下我的计算机的处理器和内存信息是好的:

昨天我发布了关于洛伦兹方程(混沌理论的经典方程)的帖子,其中一位大佬帮助我并给出了解决方案,这里是:

function f=lorenz(t,x,a,b,c)
        % solve differential equation like this
        %dx/dt=a*(y-x)
        %dy/dt=-x*z+b*x-y
        %dz/dt=xy-c*z/3
        f=zeros(3,1);% preallocate result
        f(1)=a*(x(2)-x(1));
        f(2)=-x(1)*x(3)+b*x(1)-x(2);
        f(3)=x(1)*x(2)-c*x(3)/3;
        end

和测试程序(脚本):

% test program
x0=[-2 -3.5 21];% initial  point
a=input(' enter first coefficient : ');
b=input(' enter second coefficient: ');
c=input(' enter third coefficient : ');
[t,x] = ode45(@(t,x) lorenz(t,x,a,b,c),[0 10],x0);
plot(t,x(:,1),'r'); 
title(' solution of x part');
grid on

但在 运行 那些行之后

test_program
 enter first coefficient : 10
 enter second coefficient: 28
 enter third coefficient : -8

还是运行,他说在他的个人电脑上,需要2秒,真是奇怪怎么回事?为什么它不能在我的电脑上编译?就像你看到的那样 我的笔记本电脑有很好的参数,请帮助我 - 即使现在它是 运行 所以我应该使用 ctrl-c 取消。

我得到了适合您情况的解决方案:

你的问题是 ode45 开始划分时间步并且它在 6 秒后变得非常小(1e-51e-6) - 它使 29 388 481 迭代达到 10 秒!

所以有两个重要时刻:

  1. 首先没有必要使用[0 10]时间间隔。您可以在图中看到您更早地得到了解决方案。

  2. 你的方法是coefficient-sensitive:我尝试使用其他系数值abc,它在几秒钟内计算出来.