ODE solver-using initial conditions in events function
5 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
采纳的回答
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
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
