@zqbinggong 2016-04-19T15:29:54.000000Z 字数 4144 阅读 1747

# the motion of the harmonic and anharmonic oscillator

homework of Computational Physics(level2),

oscillator.py

## Abstract

The question ask us to describe the motion of a simple oscillator with the motion equation $\frac{\partial^2x}{\partial t^2} =-k x^{ \alpha }$,where we can take $k=1$ for convenience.If we take $\alpha=1$,this is an example if an harmonic oscillator.If we take$\alpha=3$,this is an example if an anharmonic oscillator.Calculate the period of the oscillations for several different amplititudes(amplititudes in the range $0.2$ to $1$ are good choices).And in my program,I choose $amplititudes=[1,0.7,0.5,0.3]$.

## Key word

Euler methonds,oscillator,easygui

## Background

Oscillation is the repetitive variation, typically in time, of some measure about a central value (often a point of equilibrium) or between two or more different states. The term 'vibration' is precisely used to describe mechanical oscillation but used as a synonym of 'oscillation' too. Familiar examples include a swinging pendulum and alternating current power.
Oscillations occur not only in mechanical systems but also in dynamic systems in virtually every area of science: for example the beating human heart, business cycles in economics, predator-prey population cycles in ecology, geothermal geysers in geology, vibrating strings in musical instruments, periodic firing of nerve cells in the brain, and the periodic swelling of Cepheid variable stars in astronomy.

## Body

### 1Hharmonic oscillator

A simple harmonic oscillator is an oscillator that is neither driven nor damped,where we can set $\alpha=1$. It consists of a mass ''m'', which experiences a single force, ''F'', which pulls the mass in the direction of the point ''x''=0 and depends only on the mass's position ''x'' and a constant ''k''. Balance of forces for the system is

$F = m a = m \frac{\mathrm{d}^2x}{\mathrm{d}t^2} = m\ddot{x} = -k x$

Solving this differential equation, we find that the motion is described by the function

$x(t)=Acos(wt+ \varphi )$

where

$\omega = \sqrt{ \frac{k}{m} }= \frac{2 \pi }{T}$
Remark:in question3.4,we just consider the more simple situation where $\frac{\partial^2x}{\partial t^2} =-k x^{ \alpha }$,so we have $x(t)=Acos( \sqrt{k} t+ \varphi )$ and $T= \frac{2 \pi }{ \sqrt{k} }$.

The motion is periodic, repeating itself in a sinusoida fashion with constant amplitude, ''A''. In addition to its amplitude, the motion of a simple harmonic oscillator is characterized by its period ''T'', the time for a single oscillation or its frequency $f= \frac{1}{T}$ , the number of cycles per unit time. The position at a given time ''t'' also depends on the phase, $φ$, which determines the starting point on the sine wave. The period and frequency are determined by the size of the mass ''m'' and the force constant ''k'', while the amplitude and phase are determined by the starting position and velocity.

The velocity and acceleration]of a simple harmonic oscillator oscillate with the same frequency as the position but with shifted phases. The velocity is maximum for zero displacement, while the acceleration is in the opposite direction as the displacement.

The potential energy stored in a simple harmonic oscillator at position ''x'' is

$U = \frac{1}{2}kx^2$

### 2.Anharmonic oscillator

If we take $\alpha$ for other value,for example, $\alpha$ is $3$,we can obtain a anharmonic case.The anharmonic oscillator is a little more complex than the harmonic oscillator.

### 3.Euler-Cromer method

We can use Euler-Cromer methon to find the solution. The explicit progress of Euler-Cromer method is showed there:
For each time step $i$ calculate $\omega$ and $\theta$ at time step $i+1$

• $\omega _{i+1} = \omega _{i}-k \theta _{i} ^{3} dt$
• $\theta _{i+1} = \theta _{i}-k \omega _{i+1} dt$
• $t _{i+1} = t _{i}+ dt$
• Repeat for the desired number of time steps.

### 3. Implementation of the program

1.Firstly,the program pop-up a graphical interface ask you to input the value of $k$ .And our suggestion is to take $k=1$,and if you enter $0$ for $k$,another graphical interface would be popped-up to ensure your choice,because if $k=1$ , we only obtain several straight lines

2.Then,the program run ,drae the figure and save it.

3.So why don't I draw the 3D picture?----the program with vpython is writing now,please wait with patient!

## Results(with easygui)

### the graphical interface

1.If you enter 1 for $k$ ,the 'good' would be printed.

2.If you enter 0 for k, the computer would pop-up another grapthical interface to ensure your choice.Then you can click 'continue' to assert your choice,and you can click 'cancel' to re-enter the value of k

## Connclusion

1.According to the results,we draw a conclusion that period is only dependent on $k$

2.The motion of the anharmonic oscillator is also periodic.

3.With the larger $\alpha$ and smaller $k$,we have larger period.

## Acknowledgement

Thanks to Liu Wentao for his template.

• 私有
• 公开
• 删除