How can I use ode15s with a tspan of two elements?

3 views (last 30 days)
Hi, I'm using the function ode15s to solve ODE. I don't understand why, with a vector of time with only 2 elements, Matlab automatically chooses the integration step.
If I insert a vector of at least 3 elements, as I expect to see, Matlab returns a vector of the simulated time with the same length. On the contrary, it doesn't happen with a vector of 2 elements.
How can I correct this problem, in order to solve an ODE with only 2 elements in tspan?
Thank you!

Accepted Answer

Jan
Jan on 8 Apr 2021
Edited: Jan on 8 Apr 2021
Why do you assume, that this is a problem?
With applying a tspan vectors with >= 3 elements, the integrators of Matlab perform an interpolation or adjust the step size until the specified time points are reached. But even then the intermediate step sizes are taken according to the step size control. Only the output is adjusted such, that t = tspan.
You can emulate this easily if you need the first and the last value only:
[t, y] = ode15s(...)
t = t([1, end]);
y = y(:, [1, end]);

More Answers (0)

Community Treasure Hunt

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

Start Hunting!