matlab程序ode45
来源:学生作业帮 编辑:百度作业网作业帮 分类:综合作业 时间:2024/07/01 04:59:48
matlab程序ode45
用ode45求解微分方程组dx=20/7*x-yz,dy=-10y+xz,dz=-4z+xy,如何编写,还要画图.初值(3,-4,2).对初值很敏感,t=0.001:0.001:20.
function dx=myfun(t,x)
dx(1)=20/7*x(1)-x(2)*x(3);
dx(2)=-10*x(2)+x(1)*x(3);
dx(3)=-4*x(3)+x(1)*x(2);
dx=dx(:);
x0=[3,-4,2];
t0=0.001:0.001:20;
[t,x]=ode45('myfun',[0.001,20],x0); %ode45会自动调整步长
plot(t,x)
legend('x','y','z')
程序中 运行出来
Input argument "x" is undefined.
Error in ==> myfun at 2
dx(1)=20/7*x(1)-x(2)*x(3);
报错.请问是怎么回事?
用ode45求解微分方程组dx=20/7*x-yz,dy=-10y+xz,dz=-4z+xy,如何编写,还要画图.初值(3,-4,2).对初值很敏感,t=0.001:0.001:20.
function dx=myfun(t,x)
dx(1)=20/7*x(1)-x(2)*x(3);
dx(2)=-10*x(2)+x(1)*x(3);
dx(3)=-4*x(3)+x(1)*x(2);
dx=dx(:);
x0=[3,-4,2];
t0=0.001:0.001:20;
[t,x]=ode45('myfun',[0.001,20],x0); %ode45会自动调整步长
plot(t,x)
legend('x','y','z')
程序中 运行出来
Input argument "x" is undefined.
Error in ==> myfun at 2
dx(1)=20/7*x(1)-x(2)*x(3);
报错.请问是怎么回事?
![matlab程序ode45](/uploads/image/z/16900570-10-0.jpg?t=matlab%E7%A8%8B%E5%BA%8Fode45)
function dx=myfun(t,x)
dx(1)=20/7*x(1)-x(2)*x(3);
dx(2)=-10*x(2)+x(1)*x(3);
dx(3)=-4*x(3)+x(1)*x(2);
dx=dx(:);这部分保存为m函数文件
命令行运行>> x0=[3,-4,2];t0=0.001:0.001:20;[t,x]=ode45('myfun',[0.001,20],x0); %ode45会自动调整步长plot(t,x) legend('x','y','z')>> 结果![](http://img.wesiedu.com/upload/e/c0/ec080cc378c6cfc78dffeb3a6062f84c.jpg)
dx(1)=20/7*x(1)-x(2)*x(3);
dx(2)=-10*x(2)+x(1)*x(3);
dx(3)=-4*x(3)+x(1)*x(2);
dx=dx(:);这部分保存为m函数文件
命令行运行>> x0=[3,-4,2];t0=0.001:0.001:20;[t,x]=ode45('myfun',[0.001,20],x0); %ode45会自动调整步长plot(t,x) legend('x','y','z')>> 结果
![](http://img.wesiedu.com/upload/e/c0/ec080cc378c6cfc78dffeb3a6062f84c.jpg)