matlab画二阶常微分方程的状态方程代码:M文件function xdot= Chapterone(t,x)xdot=[(7.5*cos(1*t)-0.05*x(1)-1*x(2)^30)/1;x(1)];end>> t0=0;tf=20;x0=[0,0.25]';>> [t,x]=ode23('Chapterone',t0,tf,x0);提示错误:Err

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/28 03:18:51

matlab画二阶常微分方程的状态方程代码:M文件function xdot= Chapterone(t,x)xdot=[(7.5*cos(1*t)-0.05*x(1)-1*x(2)^30)/1;x(1)];end>> t0=0;tf=20;x0=[0,0.25]';>> [t,x]=ode23('Chapterone',t0,tf,x0);提示错误:Err
matlab画二阶常微分方程的状态方程

代码:M文件
function xdot= Chapterone(t,x)
xdot=[(7.5*cos(1*t)-0.05*x(1)-1*x(2)^30)/1;x(1)];
end


>> t0=0;tf=20;x0=[0,0.25]';
>> [t,x]=ode23('Chapterone',t0,tf,x0);


提示错误:
Error using odearguments (line 81)
The last entry in tspan must be different from the first entry.


Error in ode23 (line 113)
[neq,tspan,ntspan,next,t0,tfinal,tdir,y0,f0,odeArgs,odeFcn,...



matlab画二阶常微分方程的状态方程代码:M文件function xdot= Chapterone(t,x)xdot=[(7.5*cos(1*t)-0.05*x(1)-1*x(2)^30)/1;x(1)];end>> t0=0;tf=20;x0=[0,0.25]';>> [t,x]=ode23('Chapterone',t0,tf,x0);提示错误:Err
你是用的哪个版本的MATLAB?
 
从调用格式来说,这属于非常早期(大概是6.0之前)的语法(t0和tf分成两个参数写),从我手上的版本看,在6.5或2008b都是可以运行的,不会出现你贴出的错误.
 
猜测你的MATLAB版本可能是6.5之前的,对于输入参数的处理存在BUG所导致.
 
不过,建议现在应该使用新调用格式,即使用函数句柄,并且把时间范围写成一个向量:
    [t,x]=ode23(@Chapterone,[t0 tf],x0);
 
另外提醒一下,微分方程的表达式写错了,把3写成30了:
    xdot=[(7.5*cos(1*t)-0.05*x(1)-1*x(2)^30)/1;x(1)];