how to stop ode45 when one of states reach certain value

Illustration
Mohamed Aburakhis - 2023-10-23T10:40:16+00:00
Question: how to stop ode45 when one of states reach certain value

[x_dot] =derivative(t, x)   x is states [x(1).....x(4)] I need to stop the integration when x(3) reaches 0.1 when the integration stop record (t)

Expert Answer

Profile picture of John Michell John Michell answered . 2025-11-20

Opt    = odeset('Events', @myEvent);
[T, Y] = ode45(@YourFun, T, Y0, Opt);

function [value, isterminal, direction] = myEvent(T, Y)
value      = (Y(3) == 0.1);
isterminal = 1;   % Stop the integration
direction  = 0;


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!