Problem with Event Function
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I created a function file which contains my ODE which has to be solved. In each step a value is calculated: i_up = 0 or 1. If it is 0 the calculation should stop, if it is 1 it should continue. Now i wanted to use an event function like:
function [value,isterminal,direction] = events_uplift(t,y,i_up,Sys)
% Locate the time when the cylinder has uplifted
% and stop integration.
value = i_up ; % Detect i_up= 0
isterminal = 1; % 1 Stop the integration; 0 Do not stop
direction = 0; % 0 always
But when I start the calculation it just returns :"not enough input arguments". What do I have to change?
0 comentarios
Respuestas (1)
Walter Roberson
el 20 de Mzo. de 2016
If i_up is being calculated in each step, then the only way to communicate it to be available to the event function as a parameter would be by way of parameterizing the function
@(t, y) events_uplift(t,y,i_up,Sys)
where i_up, the same i_up you calculate, is a shared variable defined in the workspace that has your ode function as a nested function . And if you are going to do that, you might as well make the events_uplift another nested function of the same function and not bother passing it as a parameter.
To phrase this a different way: anything you calculate in the ode function normally vanishes and is not passed to the event function, and you need to take special steps to have the value continue to exist long enough to call the event function (and you would have to know whether the event function is called before or after the ode function.)
Important side note: event functions terminate (when so requested) when their value is positive, so if you want "1" to signal that you should continue, you should return (1 - i_up) . That would then become 0 when i_up is 1, and 0 and negative mean "continue" to ode events. When i_up is 0, 1 - i_up would be 1, a positive value, and positive values mean "terminate" to ode events.
0 comentarios
Ver también
Categorías
Más información sobre Ordinary Differential Equations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!