注册 登录
编程论坛 Matlab

微分方程错误..Error using ==> feval

慢跑20 发布于 2013-05-11 17:17, 1096 次点击
课本传染病模型SIR.
先建立M文件
function y=ill(t,x)
a=1;b=0.3;
y=[a*x(1)*x(2)-b*x(1),-a*x(1)*x(2)]';
然后再MATLAB中输入:
ts=0:50;
x0=[0.02,0.98];
[t,x]=ode45('ill',ts,x0);[t,x]
Plot(t,x(:1,),t,x(:,2)),grid,pause
Plot(x(:,2),x(:,1)),grid
function y=ill(t,x)
a=1;b=0.3;
y=[a*x(1)*x(2)-b*x(1),-a*x(1)*x(2)]';

就会:
显示错误:
如下:
??? Error using ==> feval
Undefined command/function 'ill'.

Error in ==> funfun\private\odearguments at 110
f0 = feval(ode,t0,y0,args{:});   % ODE15I sets args{1} to yp0.

Error in ==> ode45 at 173
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, ...

>>
啥问题呢?
1 回复
#2
cuijunchao2013-05-12 13:33
function [ dy ] =ill( t,x )
 dy(1)=0;
 dy(2)=0;
 a=1;b=0.3;
 dy=[a*x(1)*x(2)-b*x(1),-a*x(1)*x(2)]';
end

ts=0:1:50;
 x0=[0.02 0.98];
 [t,x]=ode45('ill',ts,x0);

 plot(ts,x(:,1)),grid
这样是可以了 数据你添上去吧
1