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
Click For Summary

Discussion Overview

The discussion revolves around solving second-order ordinary differential equations (ODEs) using MATLAB, specifically focusing on the use of the ODE45 solver. Participants explore two different models: one for an undamped spring-mass system with a time-dependent spring constant and another for a linear mass-spring system with damping and forcing. The conversation includes questions about initial conditions, solution curves, and plotting results.

Discussion Character

  • Homework-related
  • Technical explanation
  • Exploratory

Main Points Raised

  • One participant presents two questions involving second-order ODEs, asking for help with MATLAB code to solve them using ODE45.
  • Another participant suggests breaking the second-order ODE into two coupled first-order equations and provides guidance on how to structure the MATLAB function for ODE45.
  • A request is made for an example problem to illustrate the MATLAB code, indicating a need for practical examples to aid understanding.
  • Another participant directs the original poster to the MATLAB documentation, specifically the 'odefile' help entry, as a resource for further learning.

Areas of Agreement / Disagreement

The discussion does not present any consensus or resolution. Participants offer different types of assistance, but there is no agreement on a specific solution or approach to the problems posed.

Contextual Notes

Participants express varying levels of familiarity with MATLAB, indicating that some foundational knowledge may be lacking, particularly in transitioning from first-order to second-order ODEs. There is also an implication that the original poster's understanding of the mathematical concepts may not be fully aligned with their programming skills.

Who May Find This Useful

This discussion may be useful for students or individuals learning to solve second-order ODEs in MATLAB, particularly those seeking practical coding examples and guidance on using ODE45.

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
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K