作业帮 > 综合 > 作业

matlab解常微分方程

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/21 07:53:20
matlab解常微分方程
MATLAB解常微分方程运行中
创建xprim2,将此函数保存在M文件xprim2.m中:
function xprim=xprim2(t,x)
xprim=[x(1)-0.1*x(1)*x(2)+0.01*t;
-x(2)+0.02*x(1)*x(2)+0.04*t];
然后调用一个ODE算法和画出解的图形:
[t,x]=ode45(‘xprim2’,[0,20],[30;20]);
plot(t,x);
xlabel(‘time t0=0,tt=20’);
ylabel(‘x values x1(0)=30,x2(0)=20’);
中间运行正常,但是在执行根据 X2函数绘制出X1 图形的命令plot(x(:2),x(:1))时出现错误?plot(x(:1),x(:2))
|
Error:")" expected,"numeric value" found.
这次看看,程序通了.
function hhh
[t,x]=ode45(@xprim2,[0,20],[30;20]);
plot(t,x);
xlabel('time t0=0,tt=20');
ylabel('x values x1(0)=30,x2(0)=20');
function xprim=xprim2(t,x)
xprim=[x(1)-0.1*x(1)*x(2)+0.01*t;
-x(2)+0.02*x(1)*x(2)+0.04*t];