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!