Help with ODE45

1 次查看(过去 30 天)
Mike Mierlo van
Mike Mierlo van 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 CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by