Solving a 2nd order ODE in MATLAB

  • Context: MATLAB 
  • Thread starter Thread starter patso29
  • 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
7 replies · 4K views
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: