# Harmonic oscillator analytic vs. numerical

1. May 17, 2012

### the_godfather

1. The problem statement, all variables and given/known data

trying to write a program in C++ to calculate the solution of a damped harmonic oscillator and compare with the exact analytic solution. i am using the classic 4th order Runge-Kutta, which i'm fairly sure is programmed right.

2. Relevant equations

m$\ddot{x}$ + c$\dot{x}$ + kx

t = 0, x = 4, v = 0

i'm interested in the underdamped case

3. The attempt at a solution

a solution of the form

exp[rt] exists

therefore i get exp[rt](r^2m + rc + k) = 0
since exp[rt] ≠ 0
then can solve the quadratic to get a value for r

r = (- c $\pm$ $\sqrt{c^2 + 4*m*}$)/2m

now we obtain two possible solutions
for simplicity i will say that $\alpha$ = -c/2m and ω = sqrt{c^2 + 4*m*}[/itex])/2m

since, this case is underdamped ω is complex. so i rewrite as iω'. where ω' = 4*m - c^2.

my full solution then becomes

A*exp(-\alpha*t)cos(w't) + B*exp(-alpha*t)sin(ω't)

when i set the damping term, c = 0. the two solutions match. as the ω' just reduces down to \sqrt{k/m} which is the frequency for an undamped harmonic oscillator. also when i plot a graph for a simple harmonic oscillator analytically vs. my damped numerical solution to peaks shift as expected as the damping term affects the frequency of oscillation.