ODE45 change y at event

4 ビュー (過去 30 日間)
bstechel
bstechel 2019 年 10 月 4 日
編集済み: Corentin Dewez-Raszka 2020 年 9 月 24 日
Can i influence the 'y' during an ode45 at a certain event?
I want to let the ODE45 stop at a certain event, manipulate the result at that timepoint and let it run further using the manipulated result as initial condition.A basic example is this:
spawnday=250;
function [value,isterminal,direction] = half_y_at_event(t, y, spawnday)
value = [t-spawnday];
isterminal = [1];
direction = [];
end
options=odeset('Events', @half_y_at_event, 'AbsTol', 1e-8, 'RelTol', 1e-8);
[t1, y1, te, ye, ie] = ode45(@dget_y, [0 500], [y_0], options, [pars]);
ye=ye/2;
[t2, y2] = ode45(@dget_y, [0 500], [ye], options, [pars]);
Is there a possibility to combine both ODE45 into one?
Mergin the matrices later is not an option.
  2 件のコメント
darova
darova 2019 年 10 月 4 日
Using ode45 two times?
[t1, y1, te, ye, ie] = ode45(@dget_y, [0 500], [y_0], options, [pars]);
ye = ye/2;
[t2, y2] = ode45(@dget_y, [0 500]+t1(end), ye(:,end));
bstechel
bstechel 2019 年 10 月 14 日
Using 2 ODE45 Is not convenient here since the event will occur multiple times over the total timespan of the ODE45 i'm interested in.

サインインしてコメントする。

採用された回答

Steven Lord
Steven Lord 2019 年 10 月 14 日
You can use the ballode example as a model. That has an events function that stops the solver each time the bouncing ball touches the ground. It then changes the initial condition (based on the solution the solver gave when the event occurred) and starts the solver again with the new initial condition.
edit ballode
  3 件のコメント
Corentin Dewez-Raszka
Corentin Dewez-Raszka 2020 年 9 月 24 日
編集済み: Corentin Dewez-Raszka 2020 年 9 月 24 日
Hey, sorry to disturb, but I have the ame problem you did, where can I get the code for ballode ?
EDIT : nevermind, found it, thx guys
bstechel
bstechel 2020 年 9 月 24 日
編集済み: bstechel 2020 年 9 月 24 日
type: edit ballode

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by