Help with ODE45

1 回表示 (過去 30 日間)
Mike Mierlo van
Mike Mierlo van 2021 年 1 月 31 日
編集済み: Alan Stevens 2021 年 1 月 31 日
Hi,
I want to implement a ODE45 solver, but it does not work the way I want, please help!
Situation: I want to model a simple fall of an object that starts falling at a height of 10 meter with no horizontal speed. Only vertical speed and locations are relevant.
Below is my code, and I don't get why it is not working.
options = odeset('AbsTol',1e-6,'MaxStep',5); % Set some options for ODE45
[t,output] = ode45(@AircraftExit,[0:0.01:10],[10,0],options); % Set ODE45 odefcn function
global g
g= 9.81
function [bal] = AircraftExit(t,Input) % Execute equations of motion
global g
bal(1) = Input(2); % Velocity
bal(2) = -g; % acceleration
end

採用された回答

Alan Stevens
Alan Stevens 2021 年 1 月 31 日
編集済み: Alan Stevens 2021 年 1 月 31 日
global g % The value of g must be specified before using it in the function via ode45
g = 9.81;
options = odeset('AbsTol',1e-6,'MaxStep',5); % Set some options for ODE45
[t,output] = ode45(@AircraftExit,0:0.01:10,[10,0],options); % Set ODE45 odefcn function
function [bal] = AircraftExit(t,Input) % Execute equations of motion
global g
bal = [Input(2); % Velocity
-g]; % acceleration
end

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by