Plotting Two First Order ODEs and Two Second Order ODEs

Click For Summary

Discussion Overview

The discussion revolves around plotting two first-order ordinary differential equations (ODEs) and two second-order ODEs using MATLAB. Participants seek assistance with specific plotting techniques and error resolution related to defining variables in their code.

Discussion Character

  • Homework-related
  • Technical explanation

Main Points Raised

  • One participant asks how to plot y(2) versus y(1) after successfully plotting each against time.
  • Another participant suggests using the plot function with matrix indexing to achieve the desired plot.
  • There is a question about defining variables in MATLAB when converting second-order ODEs into first-order ODEs and the necessity of providing initial conditions for the solver.
  • A participant clarifies that the equations are not matrices but rather equations in terms of y(1) and y(2).
  • One participant mentions losing their documents related to the second-order ODEs and indicates they will provide more information later.

Areas of Agreement / Disagreement

Participants express uncertainty about the correct approach to plotting and defining variables in MATLAB, indicating that there is no consensus on the best solution or method to resolve the issues presented.

Contextual Notes

There are unresolved issues regarding the initial conditions required for the ODE solver and the specific definitions of variables in the context of the MATLAB code.

sara_87
Messages
748
Reaction score
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
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.
 
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.
 
ghyt y
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K