ode45 to Solve System of ODEs
Show older comments
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
Answers (2)
James Tursa
on 29 Sep 2017
Edited: James Tursa
on 29 Sep 2017
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 Comments
Matthew
on 29 Sep 2017
James Tursa
on 30 Sep 2017
Edited: James Tursa
on 30 Sep 2017
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
on 30 Sep 2017
0 votes
Categories
Find more on Numeric Solvers in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!