How do I add an input in the middle of an ode45 integration?
Mostra commenti meno recenti
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 Commenti
Walter Roberson
il 5 Ago 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
il 5 Ago 2015
Risposta accettata
Più risposte (1)
Steven Lord
il 5 Ago 2015
0 voti
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.
Categorie
Scopri di più su Ordinary Differential Equations in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!