How do I add an input in the middle of an ode45 integration?
显示 更早的评论
I have a group of odes that I'm integrating with ode45. Let's say from time 0 to 100. I want to add an instantaneous (or nearly) impulse at time 50. How would I do that?
I tried adding an if loop like below in the derivative routine, but I got the following error.
if t >= 50
original function + impulse
elseif t >= 50.1
original function
else
original function
end
Subscript indices must either be real positive integers or logicals.
2 个评论
Walter Roberson
2015-8-5
Please show the actual code you attempting to add.
original function
would be the code for calling a routine named "original" with a single argument which was the string named 'function', the same thing as
original('function')
Jordan Falgoust
2015-8-5
采纳的回答
更多回答(1 个)
Steven Lord
2015-8-5
0 个投票
I recommend solving your system of ODEs from t = 0 to t = 50, apply the impulse to the final results from that initial call to the ODE solver to generate new initial conditions, then use those new initial conditions to solve the system of ODEs from t = 50 to t = 100.
The BALLODE example does a variant of this (using the speed of the ball when it hits the ground to set its speed upward after it bounces) but since it doesn't know when the ball is going to hit the ground it needs to use an events function. You DO know when your "event" will occur, so you can just set up the ODE solver call to stop its first run at that time for adjustment.
类别
在 帮助中心 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!