matlab使用ode45函数老是报错,求助!解答出来愿意加币!

调用 "func" 时,未对输出参数 "f" (可能还包括其他参数)赋值。出错 odearguments (line 90)f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.出错 ode45 (line 115)odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);出错 NApre (line 19)[t,x]=ode45(@func,[0 70],[i0,r0]);(func是:function f=func(t,x)la=0.224676956228413 * exp( -0.06936774465917156 * t );mu=0.005191914574791744 * exp( 0.02411992774086811 * t );func=[(la-mu)*x(1);mu*x(1)];)(代码是:i0=1500,r0=400;[t,x]=ode45(@func,[0 70],[i0,r0]);到底哪里错了呀,求助!

matlab使用ode45函数老是报错,其错误在func(t,x)返回值不对应,函数要求对应值为 f,而题主返回值却为func。纠正错误即可正常计算【t,x】值。

function f=func(t,x)

la=0.224676956228413 * exp( -0.06936774465917156 * t );

mu=0.005191914574791744 * exp( 0.02411992774086811 * t );

f=[(la-mu)*x(1);mu*x(1)];

end

主程序

i0=1500;r0=400;

[t,x]=ode45(@func,[0 70],[i0,r0])

plot(t,x)

xlabel('t'),ylabel('x1(t),x2(t)')

figure(2)

plot(x(:,1),x(:,2),'b*'),grid on

xlabel('x1(t)'),ylabel('x2(t)')

温馨提示:答案为网友推荐,仅供参考
相似回答