MATLAB Answers

ode45 given a systems of equations help

1 ビュー (過去 30 日間)
Francesco Latorre
Francesco Latorre 2019 年 11 月 19 日
編集済み: James Tursa 2019 年 11 月 19 日
for an assignment, i have to use ode45 to graph the position of a system of differential equations, however these equations are too complex to be combined into a single equation with one variable. for simplicity ill use easier but similar formulas:
formula A: 1 = cos(Y) + (Y' ^ 2) + (x' ^2) + Sin(Y) - X''
formula B: sin (Y) = X'' *Cos(Y-X) + X' * Sin(Y-X) + Y''
how would i use ode45 to graph two plots: X(t) and Y(t) given these two formulas?

  0 件のコメント


回答 (1 件)

James Tursa
James Tursa 2019 年 11 月 19 日
編集済み: James Tursa 2019 年 11 月 19 日
First, look over the examples in the ode45 doc.
Then figure out the order of your system, and that will tell you the size of your state vector. You have two 2nd order equations, so that means your state vector should be 2x2 = 4 elements. Using the nomenclature of the MATLAB doc to make things easier when you read them, I am going to call this state vector y. The definition of the y elements is:
y(1) = X
y(2) = Xdot
Y(3) = Y
y(4) = Ydot
Using those definitions, you need to write a derivative function. The outline of this function will look like this:
function dy = myderivative(t,y)
dy = zeros(size(y));
dy(1) = _____; % the derivative of y(1), i.e. the derivative of X, which is Xdot
dy(2) = _____; % the derivative of y(2), i.e. the derivative of Xdot, which is Xdoubledot
dy(3) = _____; % the derivative of y(3), i.e. the derivative of Y, which is Ydot
dy(4) = _____; % the derivative of y(4), i.e. the derivative of Ydot, which is Ydoubledot
You need to fill in the blanks in the above code.
Since the derivative of X is just Xdot, the dy(1) line is easy ... it is just y(2). Similar for dy(3).
The dy(2) and dy(4) lines are more work for you. You need to solve your two equations above for Xdoubledot and Ydoubledot and then use those expressions to write code.
Once this is done, I suggest you look again at the examples in the ode45 doc, particularly the one for the system of equations. That will give you clues for writing your code that calls ode45.
Give this a shot and then come back when you have some code for us to look at that we can help you with.

  0 件のコメント





Community Treasure Hunt

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

Start Hunting!

Translated by