http://www.mathworks.com/matlabcentral/newsreader/view_thread/325435
MATLAB Central Newsreader  ODE solver
Feed for thread: ODE solver
enus
©19942015 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Thu, 27 Dec 2012 16:22:06 +0000
ODE solver
http://www.mathworks.com/matlabcentral/newsreader/view_thread/325435#894395
Qiming
Hi:<br>
<br>
I have a question using ODE solvers (say, ode45).<br>
<br>
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".<br>
<br>
As I know, ode45 is essentially a "loop", it integrates the ODE function as an adaptive stepsize or a predefined fixed step size. The functions are given as below (The following codes are only for the purpose of testing):<br>
<br>
Main function:<br>
<br>
global u COUNT;<br>
COUNT = 0;<br>
<br>
t0 = 0; tf = 5;<br>
tSpan = [ t0, tf ];<br>
y0 = [ 1; 2; 3 ];<br>
[t y] = ode45(@myode, tSpan, y0);<br>
<br>
<br>
<br>
ODE function:<br>
<br>
function ydot = myode(~,y)<br>
<br>
global u COUNT;<br>
COUNT = COUNT + 1;<br>
<br>
a = 0.01;<br>
b = 0.1;<br>
ydot (1) = a*y(1)*y(2);<br>
ydot (2) = b*y(1)*y(2)b*y(2);<br>
ydot (3) = b*y(2);<br>
<br>
u(COUNT) = y(1)+y(2)+y(3);<br>
<br>
ydot = [ydot (1) ydot (2) ydot (3)]';<br>
<br>
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 think these two values should be the same. I also tried using a fixed stepsize, but they're still different. How come they're different?<br>
<br>
Thanks for any help.<br>
<br>
Qiming

Sat, 29 Dec 2012 01:52:08 +0000
Re: ODE solver
http://www.mathworks.com/matlabcentral/newsreader/view_thread/325435#894470
Sadik
Hi Qiming,<br>
<br>
Just take a look at the details of the RungeKutta method to see how many times you need to evaluate the function.<br>
<br>
Best.

Sat, 05 Jan 2013 16:08:08 +0000
Re: ODE solver
http://www.mathworks.com/matlabcentral/newsreader/view_thread/325435#894886
Qiming
"Sadik " <sadik.hava@gmail.com> wrote in message <kblic8$3sf$1@newscl01ah.mathworks.com>...<br>
> Hi Qiming,<br>
> <br>
> Just take a look at the details of the RungeKutta method to see how many times you need to evaluate the function.<br>
> <br>
> Best.<br>
<br>
Thanks Sadik, I figured out how to fix this problem. Actually I write my own ODE solver based on 4thorder RK algorithm, and I can set the stepsize by myself.<br>
<br>
Best,<br>
<br>
Qiming