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

2nd Order ODE in MATLAB help

  1. Jan 14, 2008 #1
    Ok, so while I understand 2nd Order ODEs... I really don't understand MATLAB.

    I have 2 questions that I just can't get any code to work for:

    1
    Question: Consider the model of an undampened spring-mass system with a time-dependent spring constant k(t) given by:

    d2y/dt2 + k(t)y = 0,

    Use the ODE45-solver to obtain the solution curves satisfying the initial conditions on interval [0, 100] and function k(t). Predict the behavios as t approaches infinity and discuss the nature of the oscillations (if any)

    1) y(0) = 1, y'(0) = 1, k(t) = cos(t)

    2) y(0) = 1, y'(0) = 1, k(t) = 1+t^2


    ---------------


    2
    Question: Consider the following model for a linear mass-spring system with damping and forcing:

    d2y/dt2 + (1/5)(dy/dt) + (1/5)y = coswt, y(0) = 0, y'(0) = 0

    1) Use ODE45-solver to obtain the solution curves for values of w = 0.5, 1, 1.5, 2. Plot the solutions and estimate the amplitude A of the steady response in each case.

    2) Using the data from part 1), plot the graph of A versus w. For what w is the amplitude greatest?


    ---------------


    I know how to use ODE45 to solve a 1st Order ODE and I know how to use other parts of MATLAB (tspan, y0, plot, etc.) but I have no idea how to approach this problem (mainly due to the 2nd Order ODE) nor has my professor been the best teacher when it comes to MATLAB.

    Thanks!
     
  2. jcsd
  3. Jan 14, 2008 #2

    mda

    User Avatar

    The trick to learning Matlab is to read the documentation, and lots of doing.
    The help entry you want for this one is 'odefile'

    Make your odefun receive(y) and return(dy) two rows each
    row 1 takes y and returns dy/dt
    row 2 takes dy/dt and returns d2y/dt2

    Break the problem into two coupled first order problems.
    By definition dy(1)=y(2)...
    dy(2) is your expression for d2y/dt2 using y(1) for y and y(2) for dy/dt
     
  4. Jan 14, 2008 #3
    Could you possibly set up an example problem for me? I'm not at the lab at the moment to use MATLAB but I'd like to see it now so I can know what I'm looking for tomorrow. I'd just like to see the code so I can read thru it.
     
  5. Jan 14, 2008 #4

    mda

    User Avatar

    google 'odefile' and scroll down to the example
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?