필터 지우기
필터 지우기

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 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