ode45 to Solve System of ODEs

조회 수: 3 (최근 30일)
Matthew
Matthew 2017년 9월 28일
편집: James Tursa 2017년 9월 30일
Please see the two equations in the attachment. When Eqn 1 is integrated, it will report velocity. Similarly, when Eqn 2 is integrated, it will report coordinate location. I'm being told that I can (and must) solve both of these simultaneously with a single ode45 function call. Obviously there is an interrelationship between the two equations (i.e., change in velocity affects position and vice versa). That said, I have a basic understanding of how to use ode45, but I don't know how to set it up to solve both of these simultaneously to provide v and y.
Thanks in advance,
M Ridzon

답변 (2개)

James Tursa
James Tursa 2017년 9월 29일
편집: James Tursa 2017년 9월 29일
Set up the state as a 2-element vector y. Then define the following:
y(1) = coordinate location
y(2) = velocity
Write a derivative function for this state vector
function dydt = my_derivative(t,y,F,m)
dydt = zeros(2,1);
dydt(1) = _____; <-- you fill in this part based on derivative of y(1)
dydt(2) = _____; <-- you fill in this part based on derivative of y(2)
return
end
Then write another file to call ode45:
% Set up constants here
% Set up initial conditions here
f = @(t,y) my_derivative(t,y,F,m);
% Call ode45 here using f, a time range, and initial conditions
SIDE COMMENT: You should double check your drag equation. It doesn't look right.
  댓글 수: 2
Matthew
Matthew 2017년 9월 29일
This looks like it might be heading in the right direction, but I don't completely follow you and thus have a few follow-up questions. You mentioned this:
dydt(1) = _____; <-- you fill in this part based on derivative of y(1)
dydt(2) = _____; <-- you fill in this part based on derivative of y(2)
I don't understand what you're saying here. What do you mean that I should fill this part in based on derivatives? Do you mean this?...
dydt(1) = v
dydt(2) = F/m
Additionally, is it possible to do this for all three coordinate directions simultaneously? I suppose that may not be required since I could just loop this 3 times.
Thanks for checking my drag equation. Yes, it is correct. It basically follows Newton's 2nd Law, F=ma.
James Tursa
James Tursa 2017년 9월 30일
편집: James Tursa 2017년 9월 30일
For the dydt, yes I mean exactly that. But what does this line mean in terms of the y vector?
dydt(1) = v
The v part, in terms of the y vector definition we made above, is simply y(2). So you get
dydt(1) = y(2);
The reason for my side comment is your note says that the drag force is constant. Typically drag force is a function of velocity and is not constant. However, I am guessing that this is a simplified version of drag just for homework purposes.

댓글을 달려면 로그인하십시오.


Matthew
Matthew 2017년 9월 30일
Anybody else have some input on how to construct this scenario? There were some aspects to James' answer that weren't clear to me, so I'm still unsure how to go about this.
Thanks in advance,
M Ridzon

카테고리

Help CenterFile Exchange에서 Numeric Solvers에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by