Plotting Two First Order ODEs and Two Second Order ODEs

In summary: ODEs in terms of time. The poster knows how to plot y(1) and y(2) versus time, but does not know how to plot y(2) versus y(1). They attempted to use the plot function in Matlab, but it did not work. They are looking for a solution to this problem.For (2), the poster is trying to solve two second order ODEs by making substitutions and obtaining two first order ODEs. They tried to input this into Matlab but encountered an error because they did not define y(4). They are asking for help on how to do this.
  • #1
sara_87
763
0

Homework Statement



I have two questions:
1) If i have two first order ODE y(1) and y(2) (in terms of time), i know how to plot y(1) versus time and y(2) versus time but i don't know how to plot y(2) versus y(1)

2)I have two second order ODES X''=... and Z''=... to solve this, we make the substitutions y(1)=X, y(2)=X', y(3)=Z, and y(4)=Z'
then we have two first order ODEs: y(2)'=... and y(4)'=...
I typed this into Matlab (dydt=[(the equation for y(2)'; the equation for y(4)']) but an error came up since i didnt define y(4). how do i do this?

Homework Equations





The Attempt at a Solution


1) i tried putting:
plot(y(1),y(:,2)), and i also tried plot(y(1),y(2)) but these didnt work.


Any help would be very much appreciated.
Than you.
 
Physics news on Phys.org
  • #2
sara_87 said:

Homework Statement



I have two questions:
1) If i have two first order ODE y(1) and y(2) (in terms of time), i know how to plot y(1) versus time and y(2) versus time but i don't know how to plot y(2) versus y(1)



The Attempt at a Solution


1) i tried putting:
plot(y(1),y(:,2)), and i also tried plot(y(1),y(2)) but these didnt work.

Than you.

If you have two vectors x and y, you do plot(x,y). If you have two rows of a matrix Y, you do plot(Y(1,:),Y(2,:)) to plot the first row on the x-axis and the second on the y-axis. Similarly, if you have a matrix with two columns, you use plot(Y(:,1),Y(:,2)). Y(i,j) is the element in the i-th row and j-th column of the matrix Y. The colon (:) indicates to take all elements in that row or column. So Y(1,:) is all elements in the first row of Y.

2)I have two second order ODES X''=... and Z''=... to solve this, we make the substitutions y(1)=X, y(2)=X', y(3)=Z, and y(4)=Z'
then we have two first order ODEs: y(2)'=... and y(4)'=...
I typed this into Matlab (dydt=[(the equation for y(2)'; the equation for y(4)']) but an error came up since i didnt define y(4). how do i do this?

Homework Equations

I don't quite understand what you're saying here. Did you give the solver initial conditions for both equations? If you post the code and error I could be more helpful here.
 
  • #3
for (1), they're not matrices, they're just equations in terms of y(1) and y(2).

for (2), I've lost my documents so if i find it i'll post another time.
Thank u.
 
  • #4
ghyt y
 
  • #5


Thank you for your questions. To plot y(2) versus y(1), you can use the "plot" function in Matlab and specify the variables as plot(y(1),y(2)). This will plot the values of y(2) on the y-axis and y(1) on the x-axis.

For the second question, you can define y(4) as another variable and then include it in your dydt function. For example, you can define y(4) as y(4)=Z' and then include it in your dydt function as dydt=[(the equation for y(2)'; the equation for y(4)')]. This should resolve the error you encountered.

I hope this helps. Good luck with your plotting and solving of the ODEs!
 

What is the purpose of plotting two first order ODEs and two second order ODEs?

The purpose of plotting these equations is to visually represent the behavior and relationships between various quantities over time. This can be helpful in understanding the dynamics and patterns of a system described by these equations, and can also aid in making predictions or identifying trends.

What are first and second order ODEs?

A first order ODE is a type of differential equation that involves only the first derivative of a function. It can be written in the form dy/dx = f(x,y), where y is the dependent variable and x is the independent variable. A second order ODE involves the second derivative of a function and can be written as d^2y/dx^2 = f(x,y,y').

What is the difference between first and second order ODEs?

The main difference between first and second order ODEs is the number of derivatives involved. First order ODEs involve only one derivative, while second order ODEs involve two. This means that second order ODEs describe a more complex relationship between variables than first order ODEs.

How do you plot two first order ODEs and two second order ODEs?

To plot these equations, you will need to first solve them for the dependent variable. Then, you can use a graphing tool or software to create a graph of the function over a specific range of values for the independent variable. You can also plot multiple equations on the same graph to compare their behavior.

What information can be gained from plotting two first order ODEs and two second order ODEs?

Plotting these equations can provide important insights into the behavior of a system over time. It can help identify patterns, trends, and relationships between variables, and can also aid in making predictions and understanding the dynamics of the system. Additionally, plotting can be used to verify the accuracy of the equations and their solutions.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
992
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
760
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
541
Back
Top