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!
