Solving a 2nd order ODE in MATLAB

  • Context: MATLAB 
  • Thread starter Thread starter patso29
  • Start date Start date
  • Tags Tags
    2nd order Matlab Ode
Click For Summary

Discussion Overview

The discussion revolves around solving a second-order ordinary differential equation (ODE) in MATLAB, specifically the equation m(d²x/dt²) = -kx - β(dx/dt). Participants are exploring how to implement this in MATLAB, particularly in the context of determining the system's damping behavior (overdamped, underdamped, critically damped) based on given parameters.

Discussion Character

  • Technical explanation
  • Homework-related
  • Mathematical reasoning
  • Debate/contested

Main Points Raised

  • One participant expresses difficulty in using the ODE45 command in MATLAB to solve the given second-order ODE.
  • Another participant provides a solution to the ODE, presenting the characteristic equation and the general solution for x(t), while questioning whether it represents a harmonic oscillator.
  • Several participants mention the need to determine the conditions for overdamping, underdamping, and critical damping, but express uncertainty about how to implement this in MATLAB.
  • A participant suggests that the second-order ODE must be converted into a system of first-order ODEs to use MATLAB's ODE45 function, outlining a method involving state-variable modeling.
  • Another participant indicates they do not use MATLAB, suggesting a lack of consensus on the practical implementation of the solution.
  • There is a request for clarification on how to solve for constants given initial conditions, with some participants indicating that certain constants are already known.

Areas of Agreement / Disagreement

Participants generally agree on the need to solve the ODE and determine damping conditions, but there are multiple competing views on how to implement the solution in MATLAB. The discussion remains unresolved regarding the specific steps to take in MATLAB.

Contextual Notes

Participants have not fully clarified the assumptions regarding initial conditions or the specific values of parameters like B, λ, and ω. There is also uncertainty about the exact syntax and requirements for using MATLAB's ODE45 function.

patso29
Messages
3
Reaction score
0
So I've been trying to figure this out for a while now and all my attempts have failed, like I tried using the command ODE45 but it did not work...

this is the equation -> m(d^2x/dt^2) = −kx − β(dx/dt)
I'm given that 2λ = β/m, and and ω^2 = k/m
and I must solve for when λ^2 − ω^2 > 0
I just can't for the life of me figure out how to do this in MATLAB,
hellp is much appreciated!
 
Physics news on Phys.org
Do you want the solution or how to find the solution using matlab?

Well, all I can do is give you the solution so
\begin{array}\\m\ddot{x}=-kx-β\dot{x}\Leftrightarrow m\ddot{x}+β\dot{x}+kx=0\\
mr^2+βr+k=0\Leftrightarrow r=\frac{-β\pm \sqrt{β^2-4mk}}{2m}=^{β=2λm}_{k=mω^2}\frac{-2λm\pm \sqrt{4λ^2m^2-4m^2ω^2}}{2m}=\frac{-2λm\pm 2m\sqrt{λ^2-ω^2}}{2m}\Leftrightarrow r=-λ\pm \sqrt{λ^2-ω^2}\\
x(t)=c_1e^{(-λ+ \sqrt{λ^2-ω^2})t}+c_2e^{(-λ- \sqrt{λ^2-ω^2})t}\end{array}

It is the ode for a harmanic oscillator isn't it?
 
Last edited:
yah i basically have to find when its overdamped, underdamped and critically damped... but I need to figure out how to do it in MATLAB, like plug it in and everything, do you know how to do that?
 
patso29 said:
yah i basically have to find when its overdamped, underdamped and critically damped... but I need to figure out how to do it in MATLAB, like plug it in and everything, do you know how to do that?

Sorry, I don't use MATLAB
 
so how would I solve for what values of B give the inital conditions?
 
patso29 said:
so how would I solve for what values of B give the inital conditions?

You have B. All you need to find is c_1 and c_2 with the initial condtitions
 
You can't put in a 2nd order ODE in MATLAB directly. You have to use the state-variable model to break it into 2 1st-order ODEs and then use ode45 (RK4) method to get it.

Define a matrix Z and use the key z1 = x and z2 = x_dot (or dx/dt in Leibniz notation). Then z1_dot = z2 and z2_dot (d^2x/dt^2) = -k/m *z1 - (beta/m) * z2. The matrix Z_dot is the derivative of the matrix and has z1_dot and z2_dot as entries. You can then say that Z_dot = A*Z, where A is the matrix of your coefficients. Make a function that computes this 1st order ODE (using matrices as variables) and put it into ode45.

I forget how MATLAB likes its ode45 syntax, but that's the basics.
 
Last edited:

Similar threads

  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 6 ·
Replies
6
Views
4K
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K