For example, when N=1000 datapoints (length of each of the time series) what should be t and the integration time step, dt
t
should be your 1-by-N 'datapoints'. With ode45
, it allows you to do initial and end points only.
dt
is the durations between neighbouring time points. You don't need it for ode45
. If you need to know what Matlab does, check this article or pick up the first book in their reference list.
how to determine t
It should come from the nature of your problem.
You can start with uniform timestep. For example, t=
linspace
(0,50,10000)
.
I did a quick Google search on adaptive timesteps and the first few links seem rather good. Starting with an educational writing illustrating the concept using Euler's method.
ode45
uses adaptive timesteps of its own choosing. Their method is described in the first linked article.
The code below is for simulating the Rossler system.
Your odefun
format is right. Ofc, since we communicate only in Minimal Reproducible Example, your coefficients must be right -- though that is something you may wish to double-check.
I do not have an opinion on whether the results below would be a correct solution. (I would not wish to.)
You can experiment with different tolerance values to see if a more sensible result can be produced.
Perhaps you will find it helpful to know that I have seen strange and incorrect results from ode45
from very simple systems when my manually implemented non-adaptive RK45 and even Euler method worked as expected.
If I were you, I would simultaneously engage in a conversation at math.stackexchange on why and when adaptive ODE methods converge. Perhaps that will give you insight as to why and when ode45
results may be highly inaccurate.
I want to generate a user defined N number of points.
ode45
will decide its own timesteps. Inputting an expanded t
as opposed to just the end points tells ode45
to use the number of points you desire. It is also useful for telling ode45
to integrate backwards in time. Format for generating an 1-by-N vector is t=
linspace
(t0,tf,N)
. You do not need and cannot customize dt
for ode45
.
Using ode45
, 100k points, your constants:

Using ode113
, 100k points, a=0.2
, and ode15s
result looks similar:
