Help with ODE45

1 visualización (últimos 30 días)
Mike Mierlo van
Mike Mierlo van el 31 de En. de 2021
Editada: Alan Stevens el 31 de En. de 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

Respuesta aceptada

Alan Stevens
Alan Stevens el 31 de En. de 2021
Editada: Alan Stevens el 31 de En. de 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

Más respuestas (0)

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by