Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

ODE in Matlab

  1. Mar 20, 2008 #1
    1. The problem statement, all variables and given/known data

    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 dont 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?
    2. Relevant equations

    3. 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.
  2. jcsd
  3. Mar 22, 2008 #2
    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.

    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.
  4. Mar 23, 2008 #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.
  5. Feb 5, 2011 #4
    ghyt y
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: ODE in Matlab
  1. Matlab ode solver (Replies: 1)

  2. ODE matlab (Replies: 2)