Why do I get the error "Undefined function or variable 't'." when using an event with ode45?
Mostrar comentarios más antiguos
When trying to use an event with ode45 to find when the value of a function is 0, I get the error "Undefined function or variable 't'." Here is the code:
function [t,yforced] = forceFunction(odeFun,tSpan,y0,event)
%forceFunction Force the function to 0 and define a piecewise function
% See above.
options = odeset('Events',event);
[t,y,te,ye,ie] = ode45(odeFun,tSpan,y0,options);
y(ie:end) = 0;
yforced = y;
end
I try to use this as follows:
>> [t,yforced] = forceFunction(@(t,y) -2*t,[0,10],10,eventLessOne(t,y));
where
function [position,isterminal,direction] = eventLessOne(t,y)
%eventLessOne Event to find when the function is less than one.
% See above
position = y(1);
isterminal = 1;
direction = 0;
end
I do not know why this is happening, as this is almost directly copied from the MATLAB documentation.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Ordinary Differential Equations en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!