MATLAB: How to fix the time step in ODE45

odeode45solvetime

I want to fix the time step for my ode45 function. The code which I am using is as follows:
dt = 0.02;
tf = 600;
t = dt:dt:tf;
y0 = zeros(14,1);
[tout,yout] = ode45(@OC3_odefull,t,y0);
When I run my code, I have no control over the time step size and ode45 uses an adaptive time step. Is there any way that I can force ode45 to use the time step that I want?

Best Answer

Why do you want to fix the time step?
If you want to find the solution of the system of ODEs at specific times, you don't need to control the time step to do that. Specify the time span vector as a vector with more than two elements and the ODE solver will return the solution at the specified times. [Note that this affects the times at which the solver returns the solution, not the times used by the solver internally.]
If you have a differential equation where the value of the right-hand side depends upon the value of the solution at earlier times (and you're trying to ensure the solver computes the solution at those earlier times) you don't want to use the ordinary differential equation solvers. Use the delay differential equation solvers instead, like dde23 or ddesd.
If there's a different reason you want to control the time step, please say more about that reason.