Period of Harmonic Oscillator using Numerical Methods

In summary, the author is trying to solve a differential equation describing the motion of a harmonic oscillator and has written a Matlab programme to do so. However, he is not sure how to determine the period numerically.
  • #1
Collisionman
36
0

Homework Statement



Numerically determine the period of oscillations for a harmonic oscillator using the Euler-Richardson algorithm. The equation of motion of the harmonic oscillator is described by the following:

[itex]\frac{d^{2}}{dt^{2}} = - \omega^{2}_{0}x[/itex]

The initial conditions are x(t=0)=1 and v(t=0)=0 (i.e., position at time zero = 1 and velocity at time zero = 0) and [itex]\omega_{0} = 1[/itex].

Homework Equations



Euler-Richardson algorithm:

  1. [itex]a_{n} = \frac{dv}{dt}[/itex]
  2. [itex]V_{mid}=V_{n}+\frac{a_{n}Δt}{2}[/itex]
  3. [itex]X_{mid}=X_{n}+\frac{V_{n}Δt}{2}[/itex]
  4. [itex]a_{mid}=a_{n}+\frac{a_{n}Δt}{2}[/itex]
  5. [itex]X_{n+1} = X_{n}+{V_{mid}Δt}{2}[/itex]
  6. [itex]V_{n+1} = V_{n}+{a_{mid}Δt}{2}[/itex]

Where X, V and a are the position, velocity and acceleration, respectively.

The Attempt at a Solution



I have already written a Matlab programme to numerically solve the differential equation describing the motion using the above algorithm. I used:

[itex]\frac{dx}{dt} = 0[/itex]
[itex]\frac{dv}{dt} = 1[/itex]

However, the only thing is, I don't know how to determine the period numerically from this.
 
Physics news on Phys.org
  • #2
Aren't you supposed to use the numerically generated data to determine the period?
 
  • #3
I'm confused by your choice of initial conditions. The problem statement said to use x = 1 and v = 0, both at t = 0.
You appear to be using v = 0 and a = 1. Why the change?

When you generated your values of position versus time, did any periodic behavior manifest itself?
 
  • #4
SteamKing said:
I'm confused by your choice of initial conditions. The problem statement said to use x = 1 and v = 0, both at t = 0.
You appear to be using v = 0 and a = 1. Why the change?

When you generated your values of position versus time, did any periodic behavior manifest itself?

Sorry, I should have written the initial equation of motion as:

[itex]\frac{d^{2}x}{dt^{2}}=-\omega^{2}_{0}x[/itex]

Basically, I forgot the 'x' on the LHS when I was writing the OP. This will mean that a = - 1 (I forgot to add the 'minus' sign), because x (t=0) = 1 and w = 0. The velocity remains v (t=0) = 0.

Also, yes, periodic motion did manifest, and corresponded well with cos(t) for a time-step of 0.001.
 
Last edited by a moderator:
  • #5
jedishrfu said:
Aren't you supposed to use the numerically generated data to determine the period?

I know, but I don't know how to do this.
 
  • #6
Collisionman said:

Homework Equations



Euler-Richardson algorithm:

  1. [itex]a_{n} = \frac{dv}{dt}[/itex]
  2. [itex]V_{mid}=V_{n}+\frac{a_{n}Δt}{2}[/itex]
  3. [itex]X_{mid}=X_{n}+\frac{V_{n}Δt}{2}[/itex]
  4. [itex]a_{mid}=a_{n}+\frac{a_{n}Δt}{2}[/itex]
  5. [itex]X_{n+1} = X_{n}+{V_{mid}Δt}{2}[/itex]
  6. [itex]V_{n+1} = V_{n}+{a_{mid}Δt}{2}[/itex]
No! Let me fix that for you:
  1. [itex]a_{n} = \frac{F(x_n,\,v_n,\,t)} m[/itex]
  2. [itex]V_{mid}=V_{n}+\frac{a_{n}Δt}{2}[/itex]
  3. [itex]X_{mid}=X_{n}+\frac{V_{n}Δt}{2}[/itex]
  4. [itex]a_{mid} = \frac{F(x_{mid},\,v_{mid},\,t+Δt/2)} m[/itex]
  5. [itex]X_{n+1} = X_{n}+\frac{V_{mid}Δt}{2}[/itex]
  6. [itex]V_{n+1} = V_{n}+\frac{a_{mid}Δt}{2}[/itex]

Note the minor corrections to items 1, 5, and 6 and the *huge* correction to item 4.

With regard to items 1 and 4, what is the force F in your harmonic oscillator?
 
  • #7
D H said:
No! Let me fix that for you:
  1. [itex]a_{n} = \frac{F(x_n,\,v_n,\,t)} m[/itex]
  2. [itex]V_{mid}=V_{n}+\frac{a_{n}Δt}{2}[/itex]
  3. [itex]X_{mid}=X_{n}+\frac{V_{n}Δt}{2}[/itex]
  4. [itex]a_{mid} = \frac{F(x_{mid},\,v_{mid},\,t+Δt/2)} m[/itex]
  5. [itex]X_{n+1} = X_{n}+\frac{V_{mid}Δt}{2}[/itex]
  6. [itex]V_{n+1} = V_{n}+\frac{a_{mid}Δt}{2}[/itex]

Note the minor corrections to items 1, 5, and 6 and the *huge* correction to item 4.

With regard to items 1 and 4, what is the force F in your harmonic oscillator?

The way I initially wrote 5 and 6 here were typos, sorry. I used item 1 because that is basically what the initial acceleration is, as stated in the question: [itex]\frac{d^{2}x}{dt^{2}}=-\omega^{2}_{0}x[/itex], so I subbed in the angular frequency ([itex]\omega_{0} = 1[/itex]) and [itex]x[/itex](at [itex]t=0[/itex])[itex]=1[/itex] to get my initial acceleration [itex]a_{n}[/itex]. Using these equations which I previously wrote, the result I get resembles a cosine wave, wouldn't this correspond with the analytical solution [itex]x(t) = A(cos(t) + \phi)[/itex]?

As for the force F in the revised algorithm you stated, I think it's something in terms of gravity and mass.

As for getting the period of oscillations, as I initially wanted to find in my OP, would I be correct in saying that I'd need to use some sort of a Fourier transform function in Matlab to get the fundamental frequency(ies) and then using that to compute the period with Period = 1/Frequency?
 
Last edited:
  • #8
Ignore gravity. The equations I posted are the generic form for Euler-Richardson integration. Force divided by mass *is* acceleration, and acceleration is the time derivative of velocity. You don't need force if you know that dv/dt=-ω0x.

Your equation for amid in the opening post is incorrect. One look at the units should tell you that it cannot be correct. The first term on the right hand side has units of acceleration but the second has units of velocity. You can't add acceleration and velocity any more than you can add length and time. Units have to be commensurable in when adding, comparing, or assigning (e.g., F=ma is an assignment).

Perhaps even more importantly, the algorithm posted in the original post misses the key reason for using Euler-Richardson or any other multistage numerical integration technique: Obtaining a better estimate of *the* intermediate derivative that perfectly advances state.
 
  • #9
D H said:
Ignore gravity. The equations I posted are the generic form for Euler-Richardson integration. Force divided by mass *is* acceleration, and acceleration is the time derivative of velocity. You don't need force if you know that dv/dt=-ω0x.

So, am I right or wrong in saying that [itex]a_{n}[/itex] is just [itex]-ω^{2}_{0}x[/itex], with x(t=0)=0 and ω0 = 1?

D H said:
Your equation for amid in the opening post is incorrect. One look at the units should tell you that it cannot be correct. The first term on the right hand side has units of acceleration but the second has units of velocity. You can't add acceleration and velocity any more than you can add length and time. Units have to be commensurable in when adding, comparing, or assigning (e.g., F=ma is an assignment).

So how would I write [itex]a_{mid}[/itex]?
 
  • #10
Let's go back to your original equation:

[tex]\frac{d^2x}{dt^2}=-\omega_0^2x[/tex]

Let's rewrite it as follows:

[tex]\frac{d}{dt}\left(\frac{dx}{dt}\right)=-\omega_0^2x[/tex]

But

[tex]\frac{dx}{dt}=v[/tex]
So
[tex]\frac{dv}{dt}=-\omega_0^2x[/tex]
But [tex]\frac{dv}{dt}=a[/tex]
So, we have three equations, one for a, one for dv/dt, and one for dx/dt:

[tex]a=-\omega_0^2x[/tex]
[tex]\frac{dv}{dt}=a[/tex]
[tex]\frac{dx}{dt}=v[/tex]

These are the equations you are supposed to use recursively in conjunction with the Euler Richardson finite difference formulas.
 
Last edited:
  • #11
In my judgement, the version of the algorithm appropriate to this particular problem should be:

1. [itex]a_n=-\omega_0^2x_n[/itex]

2. [itex]v_{mid}=v_n+\frac{a_nΔt}{2}[/itex]

3. [itex]x_{mid}=x_n+\frac{v_nΔt}{2}[/itex]

4. [itex]a_{mid}=-\omega_0^2x_{mid}[/itex]

5. [itex]v_{n+1}=v_n+a_{mid}Δt[/itex]

6. [itex]x_{n+1}=x_n+v_{mid}Δt[/itex]

Chet
 
  • #12
Chestermiller said:
In my judgement, the version of the algorithm appropriate to this particular problem should be: ...

5. [itex]v_{n+1}=v_n+a_{mid}Δt[/itex]

6. [itex]x_{n+1}=x_n+v_{mid}Δt[/itex]

Chet

Ouch. What I posted is wrong. I only focused on steps 1-4. That's all for nought if the final steps are incorrect. Yours are the correct updates.
 
  • #13
Chestermiller said:
In my judgement, the version of the algorithm appropriate to this particular problem should be:

1. [itex]a_n=-\omega_0^2x_n[/itex]

2. [itex]v_{mid}=v_n+\frac{a_nΔt}{2}[/itex]

3. [itex]x_{mid}=x_n+\frac{v_nΔt}{2}[/itex]

4. [itex]a_{mid}=-\omega_0^2x_{mid}[/itex]

5. [itex]v_{n+1}=v_n+a_{mid}Δt[/itex]

6. [itex]x_{n+1}=x_n+v_{mid}Δt[/itex]

Chet

I just realized this a second ago. Thank you, Chestermiller and D H, this is great help.

As per my original question, does anything know how I find the period of the oscillations? Do I just use a Fourier transform of some kind in MATLAB to find the frequency and then use that to find the period using T = 1/f?
 
Last edited:
  • #14
You don't have to do a FT to find the period of oscillation. Your two eyeballs should do just fine.
Remember, if the displacement is periodic, the values will repeat through each period. What you have to do is use your algorithm to generate a sufficient number of displacement values until you notice that they start to repeat. Plotting these values versus time should make the periodic nature of the displacement clear. Using either format, you should be able to determine the period of oscillation.
 
  • #15
This calculation is very easy to set up on an EXCEL spread sheet. You can then easily plot the results using the EXCEL graphics capabilities.
 
  • #16
Chestermiller said:
This calculation is very easy to set up on an EXCEL spread sheet. You can then easily plot the results using the EXCEL graphics capabilities.

I would used EXCEL, but I am required to determine the frequency and therefore the period using only MATLAB.
 
  • #17
SteamKing said:
You don't have to do a FT to find the period of oscillation. Your two eyeballs should do just fine.
Remember, if the displacement is periodic, the values will repeat through each period. What you have to do is use your algorithm to generate a sufficient number of displacement values until you notice that they start to repeat. Plotting these values versus time should make the periodic nature of the displacement clear. Using either format, you should be able to determine the period of oscillation.

I think I need to determine it more accurately than just using my eyeballs. Later on in the problem sheet I've given, I am required to include damping forces, which will make it harder to determine period using the method you've described. I am required to modify the MATLAB program I've written to determine the period, so I guess I'll have to use some sort of FT function in MATLAB, unfortunately.
 
  • #18
Collisionman said:
I think I need to determine it more accurately than just using my eyeballs. Later on in the problem sheet I've given, I am required to include damping forces, which will make it harder to determine period using the method you've described. I am required to modify the MATLAB program I've written to determine the period, so I guess I'll have to use some sort of FT function in MATLAB, unfortunately.

I don't have much experience with MATLAB, but, if MATLAB has a curve fitting capability that can fit a user-supplied functional form, you can use MATLAB to fit the generated results of the calculations to a damped harmonic functional form so it can determine the period, the damping, and the phase shift automatically. At least, that is what I would try to do.

Chet
 
  • #19
Even with all kinds of damping applied, harmonic motion is still harmonic motion. All the damping is going to do is change the amplitude of the motion. You still can use a table of motion data which you generate from your numerical method to figure out the period. You just need to extract the time between motion peaks.

I would be surprised if MATLAB couldn't at least plot your motion data.
 

1. What is a harmonic oscillator?

A harmonic oscillator is a physical system that exhibits periodic motion around an equilibrium point. It is characterized by a restoring force that is proportional to the displacement from the equilibrium point.

2. How is the period of a harmonic oscillator calculated using numerical methods?

The period of a harmonic oscillator can be calculated using numerical methods by dividing the total time interval into smaller time steps and using an iterative process to approximate the motion of the oscillator at each time step. The period can then be determined by measuring the time it takes for the oscillator to complete one full cycle.

3. What are some common numerical methods for calculating the period of a harmonic oscillator?

Some common numerical methods for calculating the period of a harmonic oscillator include the Euler method, the Runge-Kutta method, and the Verlet algorithm. These methods use different approaches to approximate the motion of the oscillator and can provide varying levels of accuracy.

4. Can numerical methods be used for all types of harmonic oscillators?

Yes, numerical methods can be used for all types of harmonic oscillators, including simple harmonic oscillators and damped or driven oscillators. The specific method used may vary depending on the type of oscillator and the desired level of accuracy.

5. How do numerical methods compare to analytical methods for calculating the period of a harmonic oscillator?

Numerical methods are generally considered to be less accurate than analytical methods for calculating the period of a harmonic oscillator. However, they can be useful for more complex systems where an analytical solution is not readily available. Additionally, numerical methods can provide a visual representation of the motion of the oscillator, which can aid in understanding the behavior of the system.

Similar threads

  • Advanced Physics Homework Help
Replies
21
Views
2K
  • Advanced Physics Homework Help
Replies
16
Views
204
  • Advanced Physics Homework Help
Replies
5
Views
2K
  • Advanced Physics Homework Help
Replies
1
Views
2K
  • Advanced Physics Homework Help
Replies
2
Views
1K
  • Advanced Physics Homework Help
Replies
1
Views
2K
  • Advanced Physics Homework Help
Replies
4
Views
1K
Replies
4
Views
1K
  • Advanced Physics Homework Help
Replies
6
Views
377
Back
Top