How can I get ode solutions for the time steps I run the model instead of having values at the calculation time steps the solver chooses?

37 views (last 30 days)
Hi,
I work with ordinary differential equations, which describe an aquatic food web. So I calculate biomasses. I have in my function file 3 ode’s and use ode45 to solve them. In my third ode I use the mean of the last 30 values of the values calculated in the first and second ode.
I run my model for 3000 time steps, which I defined as 1:1:3000. But the solver does not calculate the solutions of the ode’s in the same time steps. The solver uses small time steps, when the fluctuations of the calculated values are high and bigger steps, when the fluctuations are lower. So when my system is stable, it may happen, that the solver does not calculate values for each of my predefined time step.
The problem is now that I want to use for the calculations of the means (last 30 values of ode 1&2) not the last 30 values which were calculated by the solver, but the solutions of the ode’s of the 30 time steps I defined.
So my idea was to tell the solver to use for the calculations the time steps I defined. Does anybody know how to do this? Or do you maybe have another solutions for my problem?
I hope I explained my problem clearly, if there are any questions – please ask.
It would be great if anybody could help me!
Thanks, Betty

Answers (2)

Arnaud Miege
Arnaud Miege on 22 Jun 2011
Have a look at the documentation for ode45:
tspan: A vector specifying the interval of integration, [t0,tf]. The solver imposes the initial conditions at tspan(1), and integrates from tspan(1) to tspan(end). To obtain solutions at specific times (all increasing or all decreasing), use tspan = [t0,t1,...,tf].
For tspan vectors with two elements [t0 tf], the solver returns the solution evaluated at every integration step. For tspan vectors with more than two elements, the solver returns solutions evaluated at the given time points. The time values must be in order, either increasing or decreasing.
HTH,
Arnaud

Betty Fritz
Betty Fritz on 23 Jun 2011
Thanks for your answer. But this is not the solution for my problem. The problem I have is described in the paragraph below (copied from the documentation for ode45).
Specifying tspan with more than two elements does not affect the internal time steps that the solver uses to traverse the interval from tspan(1) to tspan(end). All solvers in the ODE suite obtain output values by means of continuous extensions of the basic formulas. Although a solver does not necessarily step precisely to a time point specified in tspan, the solutions produced at the specified time points are of the same order of accuracy as the solutions computed at the internal time points.
I want the solver to use specified internal time steps, because I need the means of the last 30 values within the solving process.
Do you know what I mean?
Thanks, Betty
  1 Comment
Arnaud Miege
Arnaud Miege on 28 Jun 2011
I don't think you can access the internal time steps of the solver. You can control the step size with odeset though:
http://www.mathworks.com/help/releases/R2011a/techdoc/ref/odeset.html

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!