Why do I get the error "Undefined function or variable 't'." when using an event with ode45?
이전 댓글 표시
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.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!