Problem while solving the problem ode45

3 ビュー (過去 30 日間)
ruban ramalingam
ruban ramalingam 2018 年 11 月 22 日
コメント済み: ruban ramalingam 2018 年 11 月 25 日
function dy=pair(t,y,a,b,c)
dy(1)= -a.*y(1)+b*exp(-t);
dy(2)=(-y(1).*y(2).^2)/c;
end
>> tspan=0:0.1:0.4;
>> a=2;
>> b=4;
>> c=3;
>> [t,y]=ode45(@pair,tspan,[2 4]);
ERROR
Error using pair (line 2)
Not enough input arguments.
Error in odearguments (line 87)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 113)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
I suspect I know a bit of what's going wrong, yet I'm at a loss for how to fix it. Any help is much appreciated!
  1 件のコメント
madhan ravi
madhan ravi 2018 年 11 月 22 日
編集済み: madhan ravi 2018 年 11 月 22 日
upload pair function , ah didn't notice ,it was at the beginning XD

サインインしてコメントする。

回答 (1 件)

Torsten
Torsten 2018 年 11 月 22 日
[t,y]=ode45(@(t,y)pair(t,y,a,b,c),tspan,[2 4]);
function dy=pair(t,y,a,b,c)
dy(1)= -a.*y(1)+b*exp(-t);
dy(2)=(-y(1).*y(2).^2)/c;
dy = dy.'
end
  3 件のコメント
Star Strider
Star Strider 2018 年 11 月 22 日
ODE functions must return a column vector output. That assignment does a simple transpose operation to create ‘dy’ as a column vector.
ruban ramalingam
ruban ramalingam 2018 年 11 月 25 日
Thank you sir

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by