E = odeEvent(eventFcn)
E = odeEvent(name, value)
odeEvent stores an event function and event policy for the ode object workflow.
| Object | Purpose | Used by |
|---|---|---|
| odeEvent | Stores a reusable definition for the ode object workflow. | The matching ode property and solve. |
| Validation | Checks supported names and shapes at construction time. | Tests and errors stay explicit before integration. |
EventFcn can return only event values. In that case Direction controls the crossing direction and Response controls whether the solver proceeds or stops. Legacy event functions that return value, terminal flags, and direction are also accepted. These three outputs must contain the same number of finite elements.
Direction accepts both, increasing, or decreasing. Response accepts proceed, stop, or callback. When Response is callback, CallbackFcn is called with event time, event solution, event index, and optional problem parameters. It can return a scalar stop flag and an updated event solution.
E = odeEvent('EventFcn', @(t,y) y - 0.5, ...
'Direction', 'increasing', ...
'Response', 'stop');
problem = ode('ODEFcn', @(t,y) 1, 'InitialValue', 0, 'EventDefinition', E);
result = solve(problem, 0, 1)
function [stop, y] = myEventCallback(t, y, index)
stop = true;
end
E = odeEvent('EventFcn', @(t,y) y - 0.5, ...
'Response', 'callback', ...
'CallbackFcn', @myEventCallback);
problem = ode('ODEFcn', @(t,y) 1, 'InitialValue', 0, 'EventDefinition', E);
result = solve(problem, 0, 1)
| Version | Description |
|---|---|
| 2.0.0 | initial version |