1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Harmonic oscillator analytic vs. numerical

  1. May 17, 2012 #1
    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[itex]\ddot{x}[/itex] + c[itex]\dot{x}[/itex] + 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 [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.
  2. jcsd
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted