ODE45 Event option question

4 ビュー (過去 30 日間)
Raymond Tallarini
Raymond Tallarini 2018 年 4 月 25 日
回答済み: Raymond Tallarini 2018 年 4 月 25 日
I am trying to use the event option of ODE45 to stop integration when the velocity reaches a certain point (integrating the distance an aircaft travels down a runway). I keep getting the error "SWITCH expression must be a scalar or a character vector." Note: the project requires a Y vector with the top row being the distance down the runway and the bottom row is the velocity)
Here is my event function:
function [value,isterminal,direction] = Events(T,Y2)
% Locate the time when the velocity is over the take off velocity
global Vstall
r=double(Y2 > [0;1.2*Vstall]);
value = r; % detect
isterminal = 1; % stop the integration
direction = 0; % negative direction
Thanks!
(wouldn't let me attach thrust:
function [T]=thrust(V)
global nu
global power
global V0
T=nu*(2*power*550)/(V+V0); % twin engine => 2 * power (power in ft-lb)
end

回答 (2 件)

Torsten
Torsten 2018 年 4 月 25 日
My guess is that your r must be
r = Y2(2)-1.2*Vstall
Best wishes
Torsten.

Raymond Tallarini
Raymond Tallarini 2018 年 4 月 25 日
Well I figured it out:
In my ode45 call, I had
[T,Y2]=ode45('ode_DYDT',tspan,x0,options);
I changed it to
[T,Y2]=ode45(@ode_DYDT,tspan,x0,options);
Now it works. Why, i'm not quite sure, but I was tracing how the ballode example works and saw something about Fcnhandleused.
So I don't know why it works now, but it does.
Thanks!

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by