How do I add an input in the middle of an ode45 integration?
Show older comments
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 Comments
Walter Roberson
on 5 Aug 2015
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
on 5 Aug 2015
Accepted Answer
More Answers (1)
Steven Lord
on 5 Aug 2015
0 votes
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.
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!