In need of help with ODE45

Hi, I'm new to MATLAB and I hope you can enlighten me on the usage of ODE45.
In my main script, 'inputprompts.m', I called a function HCRSK with the ODE45 solver, as follows:
T0 = [Tc,Tsk; Tc,Tsk]; %initial values input by user
[t,T] = ode45(@HCRSK, [Tinit,Tend], T0);
Tinit and Tend are input by the user.
The HCRSK function uses the Tc and Tsk inputs and borrows the output of other functions using the same inputs. Other functions called are alpha, HSCR and HSSK. The code for the function is as follows:
function hcrsk = HCRSK(x,y)
Wt=65;
Ht=1.77;
Cbt=1.28;
Ad = 0.202.*(Wt.^0.425).*(Ht.^0.725);
a = feval(@alpha, x,y);
TCCRA = ((1-a).*Wt.*Cbt)./Ad;
hscr1 = feval(@HSCR,x,y);
Tcdot = hscr1./TCCRA;
TCSKA = (a.*Wt.*Cbt)./Ad;
hssk1 = feval(@HSSK,x,y);
Tskdot = hssk1./TCSKA;
hcrsk = [Tcdot; Tskdot]; %vector of Tc and Tsk rate equations"
Running the main script returns an error like so:
"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, ...
Error in inputprompts (line 64) [t,T] = ode45(@HCRSK, [Tinit,Tend], T0);"
HELP~~~!!

2 Comments

According to the error message, you call ODE15I instead of ODE45.
This solver has a parameter list different from ODE45.
Best wishes
Torsten.
hmm but in my main script, I typed 'ode45', not ode15I. What could have triggered the calling of ode15I instead of ode45?

Sign in to comment.

 Accepted Answer

Star Strider
Star Strider on 25 Feb 2015
Your initial conditions vector has to be the same size as the vector returned by your ODE function.

6 Comments

Maxxy’s ‘Answer’ moved here...
The ode outputs one variable (Tc or Tsk), but the odefunction within the solver requires 2 inputs (Tc and Tsk). So how do I go about doing this?
Star Strider
Star Strider on 26 Feb 2015
Edited: Star Strider on 26 Feb 2015
You can pass your ‘[Tc,Tsk; Tc,Tsk]’ matrix as an extra parameter (easy enough to do using an Anonymous Function argument to ode45), and adding the matrix to your function’s argument list. However, your initial conditions vector has to be (in your example) a (1x2) vector.
I can’t be more specific than this because I can’t figure out how your ‘HCRSK’ function works.
Like so?
T0 = [Tc, Tsk]; %initial conditions
[t,T] = ode45(@(x,y)HCRSK(Tc,Tsk), tspan, T0);
Close.
You have to include all the arguments in the function argument list:
[t,T] = ode45(2(x,y) HCRSK(x,y,Tc,Tsk), tspan, T0);
and of course the first line of your function also changes to:
function hcrsk = HCRSK(x,y,Tc,Tsk)
Thank you very much!
My pleasure!
If I solved your problem, I would appreciate it if you Accept my Answer.

Sign in to comment.

More Answers (0)

Products

Tags

Asked:

on 25 Feb 2015

Commented:

on 28 Feb 2015

Community Treasure Hunt

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

Start Hunting!