How to Solve 2nd Order ODEs in MATLAB?

  • Context: MATLAB 
  • Thread starter Thread starter SF2K4
  • Start date Start date
  • Tags Tags
    2nd order Matlab Ode
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
3 replies · 7K views
SF2K4
Messages
7
Reaction score
0
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!
 
Physics news on Phys.org
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
 
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.
 
google 'odefile' and scroll down to the example