How to Solve 2nd Order ODEs in MATLAB?

In summary, the first order problem is to find y(0) for a given value of w, and the second order problem is to find dy/dt for a given value of w.
  • #1
SF2K4
7
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
  • #2
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
 
  • #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.
 
  • #4
google 'odefile' and scroll down to the example
 

Related to How to Solve 2nd Order ODEs in MATLAB?

What is a second order ODE in MATLAB?

A second order ODE in MATLAB is a mathematical equation that describes the relationship between a function and its first and second derivatives. It can be represented as a function of two variables, typically time and position.

How do I input a second order ODE into MATLAB?

You can input a second order ODE into MATLAB using the "ode45" function. This function takes in the ODE as an input, along with the initial conditions and the range of values for the independent variable. It then solves the ODE and outputs the solution as a graph or a set of numerical values.

What is the syntax for solving a second order ODE in MATLAB?

The syntax for solving a second order ODE in MATLAB using the "ode45" function is: [t,y] = ode45(@odefun,[t0 tf],y0), where "odefun" is the function that defines the ODE, [t0 tf] is the interval for the independent variable, and y0 is the initial condition for the dependent variable.

What are the most commonly used methods for solving second order ODEs in MATLAB?

The most commonly used methods for solving second order ODEs in MATLAB are the Runge-Kutta methods, specifically the "ode45" and "ode23" functions. These methods are efficient and accurate for a wide range of ODEs.

Are there any tools or resources available in MATLAB for solving second order ODEs?

Yes, there are several tools and resources available in MATLAB for solving second order ODEs. Some of these include the "ode45" and "ode23" functions, the Symbolic Math Toolbox, and the Differential Equations Toolbox. Additionally, there are many online tutorials and forums that can provide help and guidance for solving second order ODEs in MATLAB.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
432
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
3K
Replies
3
Views
2K
Back
Top