ODE solver-using initial conditions in events function

15 ビュー (過去 30 日間)
Haocheng Yang
Haocheng Yang 2022 年 2 月 28 日
コメント済み: Haocheng Yang 2022 年 3 月 2 日
I want to solve a second-order ODE (time derivatives on x) using numerical solver like ode45:
mx''+cx'+kx+F1=0
where F1 is a nonlinear function of x and it's initial value x(0). But when x becomes x(0)-5, I want F1 to stop functioning and switch the ODE to
mx''+cx'+kx+F2=0
where F2 is just a constant and I will simulate it until x' is zero.
I know how to set event functions to make the integration stop at x'=0, but how can I switch between F1 and F2? Event functions seem not to support using initial conditions in the event describing.
One background is that F1 and F2 can be merged. When x becomes x(0)-5 and further, F1 will be a complex number while it's real part is just F2, so I can solve one equation
mx''+cx'+kx+real(F1)=0
until x' is zero. But then the simulation will not give a fine resolution at the switching point of F1 and F2. So if anyone can suggest a way to make fine resolution near the switching point of F1 and F2, that also solves my issue. Thank you!

採用された回答

Torsten
Torsten 2022 年 2 月 28 日
編集済み: Torsten 2022 年 2 月 28 日
If you want to use the event option, you can pass x(0) as an additional argument to the event function function and return control to the calling program when x(0)-5 is reached.
I suggest you just use mx''+cx'+kx+real(F1)=0 and choose tspan fine enough to resolve the switching point.
  3 件のコメント
Torsten
Torsten 2022 年 3 月 1 日
options=odeset('Events',@(t,x)onedof_events(t,x,x_initial)
instead of
options=odeset('Events',@onedof_events)
But you don't need to care how long the tspan vector is - the steps the solver takes are independent from how many elements tspan comprises.
Haocheng Yang
Haocheng Yang 2022 年 3 月 2 日
Great! Your code works for the force-switching event. And I figured out that for both methods, better resolution can be achieved by setting lower relative and absolute tolerance. Thank you for the help!

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

その他の回答 (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