ode45 to Solve System of ODEs

2 次查看(过去 30 天)
Matthew
Matthew 2017-9-28
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

Community Treasure Hunt

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

Start Hunting!

Translated by