Making sure the maximum calculated value in my function is represented in ode15s output.

조회 수: 2 (최근 30일)
I've used ode15s to solve a system of ODEs and then plotted the results. However when I do that, the peak calculated value in my function (which I would like to show on my graph) is not outputted by ode15s and hence my plotted peak does not actually show the true peak value.
Due to the stiffness of my ODEs, I cannot just increase the number of values I have, so I was wondering if there is a way to output the calculated maximum point from my function while using ode15s?
Any help would be much appreciated.
  댓글 수: 3
steve mayoh
steve mayoh 2021년 1월 8일
This is the relevant part of the function for the 3rd ODE, the results of which I want to plot against time. The solver used is ode15s and is called with set tolerances for each of the 3 ODEs.
[X,Y] = ode15s(@(t,c) process(t,c),tspan,init_cond,options);
if t < t1
dTdt(3) = 0;
elseif t >= t1 && t < t2
dTdt(3) = Q1/sum;
else
dTdt(3) = (Q1 - Q2)/sum;
end
My current plot is shown as below.
I know my function itself iterates 349 time, with one giving a max T of 540, however, from ode15s, the max T is only 537. Ideally, the peak of the graph should be 540.
Please let me know if there is anything else I can share.
Piotr Balik
Piotr Balik 2021년 1월 8일
If you have stepwise defined derivative, how about computing ode at three intervals? Start of the following one would be the last point of the former.

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2021년 1월 9일
ODE15S is designed to integrate smooth functions, as the other ODE integrators of MATLAB are. Running it with this not differentiable function replies a trajectory, which is not a "reliable result". The maximum value might be dominated by random rounding errors.
Prefer to run 3 integrations for the different time intervals using the final value of the former one as initial value for the next. After joining the trajectories you have a reliable output including the wanted maximum value.

추가 답변 (0개)

카테고리

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

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by