setting ode45 to solve at even timesteps

Hi I'm attempting to force ode45 to solve a set of odes at at least some constant timestep. I understand that ode45 is a variable step solver so it is okay if it solves at intermediate timesteps. However, I would like to have it solve at at least some regular timestep also. For example, of the timestep is 1 second then I would like the solution to at least contain solutions at seconds 0,1,2,3,4,5 ...
Do any of you know how to make this happen?
thanks, windell

3 Comments

Thanks for your answers! I've done exactly as you've suggested. I have tspan=[0:1:10000] and here is a sample of what I read for the time output where the time crosses from 0 to 1 seconds. It appears that the integrator doesnt evaluate exactly at 1 or 2 or 3 or 4 but really close to it. This is valuable to me because i want to plot just the 1 second interval solutions using a loop and its hard for my program to sort through the times if they don't land directly on the second. Any suggestions?
0.9960
0.9988
0.9993
0.9999
0.9999
1.0011
1.0017
1.0045
1.0051
1.0057
1.0057
1.0069
1.0074
1.0104
1.0109
This is really surprising for tspan=0:10000 (btw, neither :1: not the addition square brackets are required): Actually the output times are expecte to be [0, 1, 2, ...]. So where does 0.9960 come from?
Please do not describe what you have intented by the code, but the code itself. Otherwise we cannot find bugs.
Wouldn't it make sense to interp1() to exact timepoints if your data is sufficiently close ?

Sign in to comment.

 Accepted Answer

Jan
Jan on 29 Apr 2013
It is explained in the documentation how to force the intergrator to output the trajectory at certain time points: Use a vector with more than 2 elements for tspan.

More Answers (1)

If you give it an array with the times for which you want the solution instead of just the start and stop time in the TSPAN input variable. Read first paragraph of ode45 help.
HTH,

Categories

Find more on Programming in Help Center and File Exchange

Asked:

on 29 Apr 2013

Community Treasure Hunt

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

Start Hunting!