ode45 to Solve System of ODEs
2 次查看(过去 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
0 个评论
回答(2 个)
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 个评论
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!