ode45 to Solve System of ODEs
3 ビュー (過去 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!