You need to look at odeset
which creates an options structure to be used in ODE solvers, like ode45
. You're looking at changing the MaxStep
parameter.
The documentation for this (MATLAB R2015a) says:
MaxStep
- Upper bound on step size [ positive scalar ]
MaxStep
defaults to one-tenth of the tspan
interval in all solvers.
Therefore, you can make it something smaller than 0.1*tspan
... something like 1e-6
or something like that. This depends on what tspan
is, so you'll need to make it smaller than 0.1*tspan
if you want to increase the total number of time steps / output points.
As such, create an odeset
structure and override the MaxStep
parameter. The rest of the values will remain as default:
options = odeset('MaxStep', 1e-6);
Now that you're done, call ode45
on your problem:
[tout,yout] = ode45(@func, tspan, y0, options);
Simply play around with the MaxStep
until you get the desired granularity.
Minor Note
Though a bit buried, the documentation does tell you on how to change the options. This is the section that talks about how to call ode45
with options. Please take note of what is highlighted in bold. This is the documentation for MATLAB R2015a:
[TOUT,YOUT] = ode45(ODEFUN,TSPAN,Y0,OPTIONS)
solves as above with default
integration properties replaced by values in OPTIONS
, an argument created
with the ODESET
function. See ODESET
for details. Commonly used options
are scalar relative error tolerance 'RelTol'
(1e-3
by default) and vector
of absolute error tolerances 'AbsTol'
(all components 1e-6
by default).
If certain components of the solution must be non-negative, use
ODESET
to set the 'NonNegative'
property to the indices of these
components.