Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Problems in ODE solver
Replies: 1   Last Post: Dec 27, 2012 6:01 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Qiming

Posts: 10
Registered: 12/21/12
Problems in ODE solver
Posted: Dec 27, 2012 11:24 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hi:

I have a question using ODE solvers (say, ode45).

I want to save some parameter values inside the ODE function. For instance, I would like to save parameter "u" which is inside the ODE function for future use. I define the global "u", and also a counter "COUNT".

As I know, ode45 is essentially a "loop", it integrates the ODE function as an adaptive stepsize or a pre-defined fixed step size. The functions are given as below:

Main function:

global u COUNT;
COUNT = 0;

t0 = 0; tf = 5;
tSpan = [ t0, tf ];
y0 = [ 1; 2; 3 ];
[t y] = ode45(@myode, tSpan, y0);



ODE function:

function ydot = myode(~,y)

global u COUNT;
COUNT = COUNT + 1;

a = 0.01;
b = 0.1;
ydot (1) = -a*y(1)*y(2);
ydot (2) = b*y(1)*y(2)-b*y(2);
ydot (3) = b*y(2);

u(COUNT) = y(1)+y(2)+y(3);

ydot = [ydot (1) ydot (2) ydot (3)]';

The code can be ran without errors or warnings. But the things is, when I checked the workspace, "COUNT = 61", but "length(y) = 41". I also tried using a fixed stepsize, but they're still different. How come they're different?I think these two values should be the same.

Thanks for any help.

Qiming


Date Subject Author
12/27/12
Read Problems in ODE solver
Qiming
12/27/12
Read Re: Problems in ODE solver
Qiming

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.