Why do I get the error "Undefined function or variable 't'." when using an event with ode45?
Afficher commentaires plus anciens
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.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Ordinary Differential Equations dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!