- #1
the_godfather
- 22
- 0
Homework Statement
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.
Homework Equations
m[itex]\ddot{x}[/itex] + c[itex]\dot{x}[/itex] + kx
t = 0, x = 4, v = 0
i'm interested in the underdamped case
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 [itex]\pm[/itex] [itex]\sqrt{c^2 + 4*m*}[/itex])/2m
now we obtain two possible solutions
for simplicity i will say that [itex]\alpha[/itex] = -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.