How can I extract a variable that is calculated inside an ode function and pass it as an input to the event function?
Show older comments
I am using ODE45 with an event function. Inside my ode function, I perform some calculations and compute a variable (at each time step). I want this computed variable to be passed to the event function in order to check when the integration should stop.
I provide a simplified example.
Calling ode:
eventFcn = @(t,xp) myEventFunction(t,xp);
options = odeset('Event',eventFcn);
[t,xp,te,ye,ie] = ode45(@(t,xp) myODE(t,xp),tspan,xp0,options);
My ode function:
function dxp = myODE(t,xp)
..
myVar = t*xp+... % (the variable I calculate)
end
My event function:
function [value,isterminal,direction] = myEventFunction(t,xp)
% I want to have access to myVar here.
end
So, how can I extract a variable that is calculated inside an ode function and pass it as an input to the event function?
Accepted Answer
More Answers (0)
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!