注册 登录
编程论坛 Matlab

ode45解3阶微分方程,2阶我会,3阶就晕了.

lvemealone 发布于 2007-05-30 21:02, 2000 次点击
方程如下:x'''+tx''-xx'+1=0
我的m文件:
function xdot=vdpol(t,x)
xdot(3)=-t*x(3)+x(1)*x(2)-1;
xdot(2)=x(3);
xdot(1)=x(2);
x(1)=x;
窗口命令:
>> t0=0;tf=20;
>> x0=[0;0];
>> [t,x]=ode45('vdpol',[t0,tf],x0);
错误提示:
??? Attempted to access x(3); index out of bounds because numel(x)=2.

Error in ==> vdpol at 2
xdot(3)=-t*x(3)+x(1)*x(2)-1;

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, odeFcn, ...

2 回复
#2
abingchem2007-06-20 09:23
function xdot=vdpol(t,x)
xdot=zeros(3,1);
xdot(3)=-t.*x(3)+x(1)*x(2)-1;
xdot(2)=x(3);
xdot(1)=x(2);
?x0=[0;0;0];
?[t,x]=ode45('vdpol',[t0,tf],x0);

5.3版本下运行
#3
seidel2007-06-22 10:29
边界条件少啊!“index out of bounds because numel(x)=2.”
1