MATLAB Answers

0

ode45 given a systems of equations help

Asked by Francesco Latorre on 19 Nov 2019 at 19:16
Latest activity Edited by James Tursa
on 19 Nov 2019 at 19:28
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 Comments

Sign in to comment.

Products


Release

R2018b

1 Answer

Answer by James Tursa
on 19 Nov 2019 at 19:27
Edited by James Tursa
on 19 Nov 2019 at 19:28

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
end
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 Comments

Sign in to comment.