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

조회 수: 2 (최근 30일)
Elia Paini
Elia Paini 2021년 4월 8일
댓글: Elia Paini 2021년 4월 8일
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!

채택된 답변

Jan
Jan 2021년 4월 8일
편집: Jan 2021년 4월 8일
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]);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by