PDA

View Full Version : Solving a 2nd order ODE in MATLAB


patso29
Jun3-11, 09:09 PM
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!!

3.1415926535
Jun4-11, 12:58 AM
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?

patso29
Jun4-11, 10:28 AM
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?

3.1415926535
Jun4-11, 10:35 AM
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

patso29
Jun6-11, 10:17 AM
so how would I solve for what values of B give the inital conditions?

3.1415926535
Jun6-11, 10:57 AM
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

timthereaper
Jun6-11, 01:40 PM
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.

FourierFaux
Jun12-11, 06:44 PM
http://www.youtube.com/watch?v=fx3bl4oA_0U&feature=related