Physics 115/242 Comparison of methods for integrating the simple harmonic oscillator.

Similar documents
Physics 115/242 The leapfrog method and other symplectic algorithms for integrating Newton s laws of motion

Physics 115/242 The leapfrog method and other symplectic algorithms for integrating Newton s laws of motion

Computational Physics (6810): Session 8

MB4018 Differential equations

PH.D. PRELIMINARY EXAMINATION MATHEMATICS

Classical Mechanics Comprehensive Exam Solution

Differential Equations

Coordinates, phase space, constraints

MATHEMATICAL MODELLING, MECHANICS AND MOD- ELLING MTHA4004Y

Coordinates, phase space, constraints

Simple Harmonic Oscillator

Lecture 3 Dynamics 29

Problem Set 1 solutions

Logistic Map, Euler & Runge-Kutta Method and Lotka-Volterra Equations

Coupled differential equations

Chaotic motion. Phys 420/580 Lecture 10

Identification Methods for Structural Systems. Prof. Dr. Eleni Chatzi Lecture March, 2016

QUANTUM MECHANICS I PHYS 516. Solutions to Problem Set # 5

Solutions 2: Simple Harmonic Oscillator and General Oscillations

1. Consider the initial value problem: find y(t) such that. y = y 2 t, y(0) = 1.

for changing independent variables. Most simply for a function f(x) the Legendre transformation f(x) B(s) takes the form B(s) = xs f(x) with s = df

Electric and Magnetic Forces in Lagrangian and Hamiltonian Formalism

Ordinary Differential Equations

Canonical transformations (Lecture 4)

S13 PHY321: Final May 1, NOTE: Show all your work. No credit for unsupported answers. Turn the front page only when advised by the instructor!

Date: 1 April (1) The only reference material you may use is one 8½x11 crib sheet and a calculator.

15. Hamiltonian Mechanics

Lecture 6 Quantum Mechanical Systems and Measurements

Vibrations and Waves Physics Year 1. Handout 1: Course Details

Date: 31 March (1) The only reference material you may use is one 8½x11 crib sheet and a calculator.

Handout 10. Applications to Solids

Nonlinear Single-Particle Dynamics in High Energy Accelerators

Physics with Matlab and Mathematica Exercise #1 28 Aug 2012

Chaotic motion. Phys 750 Lecture 9

Figure 1: System of three coupled harmonic oscillators with fixed boundary conditions. 2 (u i+1 u i ) 2. i=0

Introduction to Path Integrals

Preliminary Examination, Numerical Analysis, August 2016

Physics III: Final Solutions (Individual and Group)

Solution: In standard form (i.e. y + P (t)y = Q(t)) we have y t y = cos(t)

Numerical solution of ODEs

Energy Level Sets for the Morse Potential

Physics with Mathematica Fall 2013 Exercise #1 27 Aug 2012

Diagonalization by a unitary similarity transformation

Solution Set Five. 2 Problem #2: The Pendulum of Doom Equation of Motion Simple Pendulum Limit Visualization...

Computational Spectroscopy III. Spectroscopic Hamiltonians

Ph 22.1 Return of the ODEs: higher-order methods

2t t dt.. So the distance is (t2 +6) 3/2

Math Assignment 5

MATH 100 Introduction to the Profession

Symmetries 2 - Rotations in Space

If the symmetry axes of a uniform symmetric body coincide with the coordinate axes, the products of inertia (Ixy etc.

MATHEMATICAL PHYSICS

01 Harmonic Oscillations

PHYSICS 234 HOMEWORK 2 SOLUTIONS. So the eigenvalues are 1, 2, 4. To find the eigenvector for ω = 1 we have b c.

Oscillatory Motion. Simple pendulum: linear Hooke s Law restoring force for small angular deviations. small angle approximation. Oscillatory solution

Oscillatory Motion. Simple pendulum: linear Hooke s Law restoring force for small angular deviations. Oscillatory solution

Quantum Mechanics C (130C) Winter 2014 Assignment 7

Physics 215 Quantum Mechanics 1 Assignment 5

Parallel-in-time integrators for Hamiltonian systems

Physically Based Modeling: Principles and Practice Differential Equation Basics

Problem 1: A 3-D Spherical Well(10 Points)

Section 3: Complex numbers

Observations on the ponderomotive force

Problem 1: Lagrangians and Conserved Quantities. Consider the following action for a particle of mass m moving in one dimension

Differential Equations 2280 Sample Midterm Exam 3 with Solutions Exam Date: 24 April 2015 at 12:50pm

Math 142-2, Homework 1

Physically Based Modeling Differential Equation Basics

Second quantization: where quantization and particles come from?

Angular momentum. Quantum mechanics. Orbital angular momentum

Problem 1: Spin 1 2. particles (10 points)

Updated 2013 (Mathematica Version) M1.1. Lab M1: The Simple Pendulum

in terms of the classical frequency, ω = , puts the classical Hamiltonian in the form H = p2 2m + mω2 x 2

Each problem is worth 34 points. 1. Harmonic Oscillator Consider the Hamiltonian for a simple harmonic oscillator. 2ml 2 0. d 2

Solutions to exam : 1FA352 Quantum Mechanics 10 hp 1

c 1 v 1 + c 2 v 2 = 0 c 1 λ 1 v 1 + c 2 λ 1 v 2 = 0

Physics 115/242 Romberg Integration

Hamiltonian. March 30, 2013

REVIEW: The Matching Method Algorithm

Physics 351, Spring 2017, Homework #2. Due at start of class, Friday, January 27, 2017

Notes on basis changes and matrix diagonalization

NORMAL MODES, WAVE MOTION AND THE WAVE EQUATION. Professor G.G.Ross. Oxford University Hilary Term 2009

1 Heisenberg Representation

Exam Question 6/8 (HL/OL): Circular and Simple Harmonic Motion. February 1, Applied Mathematics: Lecture 7. Brendan Williamson.

Math 1302, Week 8: Oscillations

Seminar 6: COUPLED HARMONIC OSCILLATORS

28. Pendulum phase portrait Draw the phase portrait for the pendulum (supported by an inextensible rod)

PHY 407 QUANTUM MECHANICS Fall 05 Problem set 1 Due Sep

Conservation of Linear Momentum : If a force F is acting on particle of mass m, then according to Newton s second law of motion, we have F = dp /dt =

Modal Decomposition and the Time-Domain Response of Linear Systems 1

Math 312 Lecture Notes Linear Two-dimensional Systems of Differential Equations

Linear Algebra and ODEs review

Two dimensional oscillator and central forces

Final Exam Spring 2014 May 05, 2014

MATH 213 Linear Algebra and Ordinary Differential Equations Spring 2015 Study Sheet for Final Exam. Topics

Chm 331 Fall 2015, Exercise Set 4 NMR Review Problems

Homework 1. Due Tuesday, January 29.

C. Show your answer in part B agrees with your answer in part A in the limit that the constant c 0.

Computational project: Modelling a simple quadrupole mass spectrometer

Implications of Time-Reversal Symmetry in Quantum Mechanics

u n 2 4 u n 36 u n 1, n 1.

Transcription:

Physics 115/4 Comparison of methods for integrating the simple harmonic oscillator. Peter Young I. THE SIMPLE HARMONIC OSCILLATOR The energy (sometimes called the Hamiltonian ) of the simple harmonic oscillator is E = p m + 1 kx (1) where m is the mass, k is the spring constant, and p = mẋ is the momentum. In the numerical examples we will set m = k = 1 so the angular frequency, ω and period, T, are given by ω = k m = 1, T = π ω = π. () We also have E = p +x (a const.) (3) Hence a phase space plot, i.e. the trajectory in the x-p plane, should be a circle of radius E. Following standard practice when solving ODE s numerically, Newton s equation of motion, ẍ = x, (4) will be written as two first order differential equations ẋ = p, (5) ṗ = x. (6) We will numerically integrate these equations for three methods that have been described in class: Euler method, second order Runge Kutta (RK), fourth order Runge Kutta (RK4), with initial conditions, x = 1,p = 0. Hence E = 1 and the radius of the circle in the phase space plots is unity. We will use a time step h = 0.0T so it takes 50 time steps to go perform one cycle of the oscillator.

The formulae for stepping forward in time the differential equations (5) and (6) are: Euler method x n+1 = x n +hp n, p n+1 = p n hx n. (7) second order Runge Kutta (RK) k x 1 = p n, k p 1 = x n, (8a) k x = p n +hk p 1, kp = (x n +hk x 1), (8b) x n+1 = x n + h (kx 1 +k), x p n+1 = p n + h (kp 1 +kp ). (8c) fourth order Runge Kutta (RK4) k x 1 = p n, k p 1 = x n, (9a) k x = p n + h kp 1, kp = (x n + h kx 1), (9b) k x 3 = p n + h kp, kp 3 = (x n + h kx ), (9c) k x 4 = p n +hk p 3, kp 4 = (x n +hk x 3), (9d) x n+1 = x n + h 6 (kx 1 +k x +k3 x +k4), x p n+1 = p n + h 6 (kp 1 +kp +kp 3 +kp 4 ). (9e) Below we give numerical results obtained by iterating these equations. However, the solutions can also be obtained analytically as shown in Appendix A. II. EULER METHOD Figure 1 show that the energy very quickly deviates from its correct value and grows without bound. The phase space plot is badly in error even after one cycle. This illustrates that the Euler method is terrible and so I don t recommend its use. III. SECOND ORDER RUNGE-KUTTA (RK) The first figure in Fig. shows that the energy deviates from its exact value much more slowly than with the Euler method and the phase space plot shows that one cycle is tracked pretty

3 FIG. 1: Numerical results for the Euler method accurately, within the thickness of the lines. (Remember the exact phase space plot is a circle of radius unity.) Hence, if you want a simple scheme, use RK but not Euler.

4 FIG. : Numerical results for second order Runge-Kutta. IV. FOURTH ORDER RUNGE-KUTTA (RK4) Figure 3, which has a highly blown up scale on the vertical axis, shows that RK4 keeps the energy constant to very high precision. All in all, RK4 is very accurate but quite simple and so is the method of choice for many people. Combined with adaptive stepsize control (not necessary

5 FIG. 3: Numerical results for fourth order Runge-Kutta. for the simple harmonic oscillator, and not covered in this course) it is very powerful. A phase space plot (not shown) looks essentially perfect. V. ANHARMONIC OSCILLATOR We conclude by showing in Fig. 4 some results for an anharmonic oscillator using the RK method. We take the potential energy to be V(x) = x6 6, (10) which is close to zero for x < 1 and then has very steep (almost vertical) walls at x = ±1. Hence the particle will travel with almost constant velocity for x < 1, and will rebound suddenly when it gets to x = ±1. The figures below show that this expected behavior is well reproduced by RK.

6 FIG. 4: Numerical results for the anharmonic (x 6 /6) potential using RK. Appendix A: Analytical results for the simple harmonic oscillator The results for the simple harmonic oscillator found above numerically can also be obtained analytically, as we show in this appendix. One can write the formulae used in the this handout to step forward by one time step in matrix

7 notation as x n+1 = A x n, (A1) p n+1 p n where A is a matrix. For the simple harmonic oscillator the matrix A is constant, i.e. independent of x and p, and, for the numerical methods described here, has the form A = c d, (A) d c where c are d are constants which are different for the different numerical schemes. For h 0 we will see below that that c 1 and d h. The eigenvalues of A are λ1 = c ± id, which can be written in polar form as λ1 = re ±iθ, (A3) where r = c +d, θ = tan 1 (d/c), (A4) so, for h 0,r 1 and θ h. The eigenvectors actually don t depend on c and d are are given by e (1) = 1 1, e () = 1 1. i i (A5) Although A is not Hermitian, so its eigenvalues are complex, it is normal which means that it commutes with its Hermitian conjugate (as is easily checked) 1. This means that it can be diagonalized by a unitary transformation, and so the eigenvectors are orthogonal, as can easily be verified in Eq. (A5). Because the elements of A are constants, we can step forward n time steps just by taking the n-th power of A, i.e. x n = A n x 0, (A6) p n p 0 The n-th power of a matrix is conveniently found by diagonalizing A. We have U AU = D, (A7)

8 where D = λ 1 0 0 λ (A8) is a diagonal matrix with the eigenvalues λ 1 and λ on the diagonal, and U is the (unitary) matrix ) U = ( e (1), e () = ex (1) ex () (A9) e p (1) ep () formed by stacking the normalized (column) eigenvectors e (1) and e () side by side. Hence A = U DU, (A10) and so A n = U λn 1 0 U, 0 λ n (A11) where we used that U U = I, the identity matrix. Substituting Eq. (A11) into Eq. (A6), and using the initial condition that x 0 = 1,p 0 = 0, we have x n = U λn 1 0 U 1 p n 0 λ n 0 = ex (1) ex () λn 1 0 e p (1) ep () 0 λ n = ex (1) ex () λn 1 ex (1) e p (1) ep () λ n ex () λ n α e x (α) α=1, = λ n αe p (α) ex. α=1, (α) ex (1) e x () (A1) Time is given by t = nh. Hence, using Eqs. (A3), (A5) and (A1), the numerical solution is given by and x(t) = e(ln(r)/h)t cos[(θ/h)t], p(t) e (ln(r)/h)t sin[(θ/h)t] (A13) E = r n = e (ln(r)/h)t, (A14)

9 where r and θ are given by Eq. (A4). For h 0 these results go over to the exact solution, x(t) = cost, p(t) = sint, E = 1, since θ h and, as we shall see, in this limit, r 1+O(h k ) where k > 1. We now give results for the different numerical schemes used in this handout. Some of the detailed calculations are done in a Mathematica notebook, which is also on the class web site (in a pdf version) at http://young.physics.ucsc.edu/115/ode solve.nb.pdf. 1. Euler From the formulae for the Euler method in Eq. (7) we find A = 1 h, h 1 (A15) so λ1 = 1±ih and hence, from Eq. (A3), we have r = 1+h = 1+ h +, θ = tan 1 (h) = h h3 +. (A16) 3 If follows from Eq. (A14) that [ ln(1+h ) E = exp h which agrees precisely with the data for E in Fig. 1. ] t ] exp[ht], (A17). RK From the formulae for RK in Eq. (8) I find A = h 1 h h 1 h, (A18) so λ1 = 1 h /±ih and hence, from Eq. (A3), we have r = 1+h 4 /4 = 1+ h4 8 +, θ = tan 1 (h/(1 h /)) = h+ h3 +. (A19) 6 If follows from Eq. (A14) that which agrees precisely with the data for E in Fig.. [ ln(1+h 4 ] [ ] /4) h 3 E = exp t exp h 4 t. (A0)

10 3. RK4 With some help from Mathematica I find that the formulae for RK4 in Eq. (9) give A = +h4 /4 h h 3 /6, h+h 3 /6 1 h +h4 /4 1 h (A1) so λ1 = 1 h /+h 4 /4±i(h h 3 /6) and hence, from Eq. (A3), we have If follows from Eq. (A14) that r = 1 h 6 /7+h 8 /576 = 1 h6 +, (A) 144 θ = tan 1 ((h h 3 /6)/(1 h /+h 4 /4)) = h h5 +. (A3) 10 [ ln(1 h 6 /7+h 8 ] ] /576) E = exp t exp [ h5 h 7 t, (A4) which agrees precisely with the data for E in Fig. 3. 4. Comments Note that the correction to the energy for the Euler method, given in Eq. (A17) is of order h, as expected since this is a first order method. However, for RK and RK4, the correction to the energy given in Eqs. (A0) and (A4) respectively is one higher order than expected, O(h 3 ) for RK whereas O(h ) is expected since RK is a second order method, and O(h 5 ) for RK4 whereas O(h 4 ) is expected since RK4 is a fourth order method. This leads to better than expected long time stability for these methods. Is this is special feature of the simple harmonic oscillator or true more generally? I don t have a definitive answer but I have experimented numerically with RK and RK4 for an anharmonic oscillator and found that the energy change, at fixed time, varies with h in the same way as for the simple harmonic oscillator, namely O(h 3 ) for RK and O(h 5 ) for RK4. Enhanced long-term stability for Runge-Kutta methods for oscillator problems therefore seems to be an unexpected, and as far as I can see an unpublicized, bonus of these methods. Note, however, that the error in x(t) and p(t) is that expected for RK and RK4, since θ/h, which is unity in the exact solution according to Eq. (A13), is 1+O(h ) for RK from Eq. (A19), and 1+O(h 4 ) for RK4 from Eq. (A3). Thus the error in the phase of the oscillation is of the order expected for RK and RK4, but the error

11 in the amplitude is of one higher order. Curious. 1 The matrix A is only normal because its off-diagonal elements are equal in magnitude which, in turn, comes from our setting m = k = 1, where m is the mass and k the force constant. If we put back general values of m and k then A is not normal, and the eigenvectors are not orthogonal so the matrix of eigenvectors U is not unitary. We therefore have to use U 1 instead of U in Eqs. (A7), (A10), (A11), and (A1). The end result is almost the same as what we find here in which we set m = k = 1. The differences are that the time step h has to be multiplied everywhere by k/m (which has the dimensions of (time) 1 ; note that t appears in the combination t/h in the solution given in Eq. (A13) so t is multiplied by m/k, the natural unit of time), the expression for the momentum has to be multiplied by mk, and the expression for the energy has to be multiplied by k.