Harmonic oscillator analytic vs. numerical

In summary, the conversation is about a person trying to write a program in C++ to calculate the solution of a damped harmonic oscillator and compare it with the exact analytic solution. They are using the classic 4th order Runge-Kutta method and are interested in the underdamped case. They discuss the solution of the form exp[rt] and how it can be rewritten as a quadratic equation to solve for the value of r. They also mention that in the underdamped case, the ω is complex and can be rewritten as iω'. They then provide their full solution and discuss how it matches the undamped case when the damping term is set to 0. However, when they set the damping term to other values
  • #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.
 
Physics news on Phys.org
  • #2
however, when i set the damping term to values other than 0, i do not get the expected result. the peaks do not shift as much as they should and the graph does not look as expected.i am unsure of what i am doing wrong and would appreciate any help or advice. thank you in advance.
 

Related to Harmonic oscillator analytic vs. numerical

1. What is the difference between a harmonic oscillator analytic and numerical solution?

An analytic solution of a harmonic oscillator refers to a closed-form mathematical expression that can predict the motion of the oscillator at any given time. In contrast, a numerical solution uses numerical methods and algorithms to approximate the motion of the oscillator over time.

2. Which method is more accurate for solving a harmonic oscillator?

Analytic solutions are generally considered more accurate since they provide an exact solution. However, the accuracy of a numerical solution can be improved by increasing the number of data points used in the calculation.

3. What are the advantages and disadvantages of using an analytic solution for a harmonic oscillator?

The main advantage of using an analytic solution is that it provides an exact solution that can be easily derived and understood. However, it may not be feasible for complex systems and may not accurately model real-world conditions.

4. How are numerical solutions used to solve a harmonic oscillator?

Numerical solutions involve breaking down the motion of the oscillator into small time intervals and using numerical methods such as Euler's method or Runge-Kutta method to calculate the position and velocity at each interval. This process is repeated until the desired time interval is reached.

5. Which method is more commonly used in scientific research and why?

Numerical solutions are more commonly used in scientific research as they can handle complex systems and are more versatile in modeling real-world conditions. However, analytic solutions are still used in simpler systems or as a benchmark for numerical methods.

Similar threads

  • Advanced Physics Homework Help
Replies
16
Views
275
  • Introductory Physics Homework Help
Replies
2
Views
472
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Advanced Physics Homework Help
Replies
1
Views
2K
Replies
4
Views
1K
Replies
7
Views
682
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
  • Quantum Physics
Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • Advanced Physics Homework Help
Replies
4
Views
1K
Back
Top