Help with ODE45

3 views (last 30 days)
Mike Mierlo van
Mike Mierlo van on 31 Jan 2021
Edited: Alan Stevens on 31 Jan 2021
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

Accepted Answer

Alan Stevens
Alan Stevens on 31 Jan 2021
Edited: Alan Stevens on 31 Jan 2021
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

More Answers (0)

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!