error with using ode45

i am writing this simple code and it is showing error as below... i dont knw why i am using matlab 2011b
function dydt = react(t,y)
% Solve the kinetics example
dydt = zeros(size(y));
% Parameters
k1 = 5; k2 = 2; k3 = 1;
A = y(1);
B = y(2);
C = y(3);
dydt(1) =k1*A + k2*B;
dydt(2) = k1*A*(k2+k3)*B;
dydt(3) = k3*B;
error is as follows
Error using feval
Undefined function 'react' for input arguments of type 'double'.
Error in odearguments (line 88)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 114)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...

回答 (2 件)

Kelly Kearney
Kelly Kearney 2014 年 10 月 17 日

0 投票

How are you calling ode45? And where did you save the reac.m function? The error indicates that ode45 isn't seeing the react function it on your path, and therefore can't apply the solver to it.

1 件のコメント

Devyani
Devyani 2014 年 10 月 17 日
my file is in the same folder which is open.i am using ode45 as follows:
[t,c]=ode45('react',[0 5],[1 0 0]);

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

Star Strider
Star Strider 2014 年 10 月 17 日

0 投票

You need to include an ‘@’ sign to create a function handle for ‘react’ in your ode45 call:
[t,y] = ode45(@react, tspan, y0);

5 件のコメント

Devyani
Devyani 2014 年 10 月 17 日
i am doing that...putting the functin file as 'react'
Star Strider
Star Strider 2014 年 10 月 17 日
I had no problem getting your function to run with the ode45 call I posted.
Change yours to:
[t,c]=ode45(@react,[0 5],[1 0 0]);
and see if that works.
Devyani
Devyani 2014 年 10 月 18 日
i deleted the file... created again the function file.. and then it started running :)
Star Strider
Star Strider 2014 年 10 月 18 日
I am happy you got it running. I had no problems at all running your ‘react’ ODE function with the ode45 call I used. It ran perfectly for me in R2014b. Did you change your ode45 call to what I suggested, or did you keep it as in your original code?
Devyani
Devyani 2014 年 10 月 18 日
I kept it with my riginal code... i deleted the file.. closed matlab and the again created the function file after sometime.. it workd... :p

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

カテゴリ

タグ

質問済み:

2014 年 10 月 17 日

コメント済み:

2014 年 10 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by