Numerical Solution of Second Order Differential Equations © by Theresa Julia Zielinski Department of Chemistry, Medical Technology, and Physics Monmouth University West Long Branch, NJ 07764-1898 and Danny G. Miles, Jr. Department of Science Mount St. Mary's College Emmitsburg, MD 21727 miles@msmary.edu tzielins@monmouth.edu © Copyright Theresa Julia Zielinski and Danny G. Miles, 1997. All rights reserved. You are welcome to use this document in your own classes but commercial use is not allowed without the permission of the authors. I. Introduction In this document we will explore the use of numerical methods for solving second order differential equations. As an illustration of this technique we choose both the classical and quantum mechanical harmonic oscillator problems. If you check your class notes or your text book you will find the solutions to the differential equations for both the classical and quantum mechanical harmonic oscillator. In the classical case the solutions were written easily. For the quantum mechanical oscillator the solutions consisted of polynomials that were obtained by requiring that these solutions were well behaved functions. This was not a trivial exercise as those of us who worked through the details can testify. Even though we have the closed form solutions for both types of the harmonic oscillator problem there are still some ideas we can extract about using mathematics to study physical systems when we approach the oscillator problems in a different way. In fact most of the interesting problems in chemistry do not have differential equations that can be solved exactly. So suppose you did not know the analytic solutions to the classical and quantum mechanical oscillator differential equations. Is there a method that you could use to understand the properties of the harmonic oscillator solutions without requiring explicit solution of the differential equations. In other words is it possible to use a method that would produce numerical answers for the differential equations? We would then plot these answers and visualize the solutions. In the case of the harmonic oscillator we would then also be able to compare our results with the known solutions and make a preliminary assessment of the value of numerical methods. In this Mathcad document we will explore a technique for finding graphical solutions to differential equations. The method is numerical rather than analytical, i.e. the analytical form found by direct solution of the differential equation is not used. The differential equation is written and the graphical solution bracketed by successive approximations to a fitting parameter. The choice of fitting parameter and variations in it are guided by inspection of the graphical behavior of the function at the boundaries of the physical model described by the differential equation. The function must satisfy these boundary conditions. In the case of the classical harmonic oscillator described in the background section of this document, at time zero the function X(t) equals the maximum extension of the oscillation and at this point the first derivative of X(t) equals zero. Furthermore the range of the numerical solution extends from time = 0 to time = the period of the oscillation. Created: January 29, 1996 Updated: July 10, 1997 numer1.mcd Authors: Theresa Julia Zielinski and Danny G. Miles 1 II. Goal To provide an introduction to the use of numerical methods for solving quantum chemistry problems. III. Prerequisites 1. College calculus including differentials and integrals. You should know what a second derivative is. 2. Basic skills with Mathcad. IV. Objectives 1. Explain the relationship between a physical model and the differential equation representing that model. 2. Discuss the relationship between the shape of the curves that are solutions to differential equations and the properties of the physical system described by the differential equations. 3. Compare and contrast the analytic solutions of the harmonic oscillator classical model and quantum mechanical oscillators to each other. 4. Compare and contrast the graphical solutions obtained by numerical methods for both oscillators. V. Background First we can review some of the basic ideas about the classical harmonic oscillator model and equation. The equations in this section of this document are not Mathcad active. They are images inserted into the text by paste/special/picture from equations written in MSWord6.0. The differential equation for the classical harmonic oscillator is: d 2 X( t ) k = − X( t ) or 2 dt m (1) && = − k X( t ) X m A standard approach for finding the solution to a differential equation like this is to try a guess for the solution to this differential equation. A good choice would be some oscillatory function like a sine or cosine function. A better guess would be a sum of the two possibilities as written next. X(t ) = A cos(b t ) + B sin( b t) (2) Next use the boundary conditions to determine A and B. One boundary condition we will impose is that at time zero the value of X(0) is the maximum extension of the spring. This maximum value of X is the amplitude of the oscillation, namely AMP. so AMP = A cos(b 0) = A Created: January 29, 1996 Updated: July 10, 1997 numer1.mcd (3) Authors: Theresa Julia Zielinski and Danny G. Miles 2 Now we must determine the value for B. For this we do the following: First write X( t) = AMP cos(b t ) + B sin( b t ) (4) Take the derivative with respect to t to get & ( t) = −AMPb sin (bt) + Bb cos(bt) X (5) Then impose another boundary condition, namely that & (0) = 0 when t = 0 then X ∴ B=0 so X(t ) = AMP cos(b t) (6) substitute equation 6 into equation 1 to find b b2 = b= k m k =ω m (7) Question: Write the final solution to the classical harmonic oscillator differential equation. Provide the units for k and the significance of k for the oscillator. Describe how k can be used to model the strength of a chemical bond. Created: January 29, 1996 Updated: July 10, 1997 numer1.mcd Authors: Theresa Julia Zielinski and Danny G. Miles 3 VI. Numerical Integration of a Differential Equation Given a differential equation of the form d2ψ(x)/dx2 = -f(x)ψ(x) we can predict the value of f(x+∆) given values for f(x) and f(x-∆) where ∆ is a small increment. The algorithm for doing this was described by J. S. Bolemon1 in the American Journal of Physics. Equation 8 is the algorithm obtained by using a Taylor series expansion (see the Bolemon paper): ∆2 2ψ n − ψ n −1 + f n −1ψ n −1 + 10 f n ψ n 12 ψ n +1 = ∆2 1 − f n +1 12 ( where ψ n ≡ ψ( xn ), ψ n ±1 = ψ(x n ± ∆), and fn = f (x n ) ) , (8) . Equation 8 may seem intimidating as we do not know at first glance where to get the values for the various components on the right side of the equation. Perhaps we should guess as we did when solving the classical harmonic oscillator equation in the background section of this document. Our guess must be informed by the physical model we are studying. Using the model first choose a range over which to calculate ψ. Next choose starting points for ψ0 and ψ1. Usually we know one or more conditions for the physical system. These permit us to choose appropriate starting values for ψ and from there we can step through the algorithm. What we must keep in mind is that this algorithm for solving a second order differential equation depends on the fact that the function that satisfies the differential equation is a smoothly varying one like a sine or cosine function. Created: January 29, 1996 Updated: July 10, 1997 numer1.mcd Authors: Theresa Julia Zielinski and Danny G. Miles 4 VII. The Classical Harmonic Oscillator Using the Numerical Solution Algorithm In this section we will examine the implementation of the algorithm step by step. After analyzing the process you will be directed to apply it to the quantum mechanical harmonic oscillator. Later you will also be able to use another Mathcad document2, 3 to explore the solutions to the radial function for a spherical potential problem. You will then be better able to describe and interpret two of the classic quantum chemistry models that lie at the core of the discipline. So now let's get started. First write the differential equation with f(t) being a constant k/m: d 2 X( t ) d t2 To use this numerical method make a grid that spans the range of the problem. Here we set the grid for 300 computed points. This will adequately span the range for this and most problems. We need a large number of points so that the distance between points throughout the whole range is small. ----------------------------------. Next choose values for any parameters that appear in the differential equation. In the equation in this introductory example this is the constant k. For simplicity let k=1 and m=1. You are free to change k later as it is defined as a global variable below. Changing m would require adjusting the algorithm equation for Xi. Since initially we want to focus on k we will not include m in the equations to follow. k . X( t ) m n This equation is toggled off. 300 m 1 k 1 ---------------------------------------------------Mathcad will plot the computed 300 points using the difference algorithm shown in equation 8. The solutions appear as plots of X(t) versus t. tmin 0 tmax 5 ∆ ----------------------------------------------------Here we set the time scale range for the problem. For the simple classical harmonic oscillator the range here is the period of the oscillation. You may choose any values to start. These too can be changed later. In differential equations for real physical situations the range will be determined by the physical context of the problem. Experience will allow you to set good ranges. tmax tmin n i 0 .. n ti tmin Created: January 29, 1996 Updated: July 10, 1997 i. ∆ -----------------------------------------------------Compute the ∆ parameter. ∆ is the spacing between the grid points. In effect tmax is the period of the oscilation. ---------------------------------------------------Now step through the grid to generate the ti values numer1.mcd Authors: Theresa Julia Zielinski and Danny G. Miles 5 ---------------------------------------------------- X0 4 X1 4.001 Set the initial values for X(t). The algorithm depends on the difference between successive estimates of X(t) as the calculation steps through all the i values of the grid. The choice of the two initial values for the function X(t) is somewhat arbitrary but depends on the system you are studying. For the simple function in this initial exercise you can use other values for X1 and the result will be the same. Other functions that you may try in a Quantum Chemistry course are more sensitive and require that the two initial values for the function be rather closely spaced. Only trial and error and experience will tell you how to proceed. This is part of the process of becoming an expert problem solver. Question: Give a description of the physical system where X0 = 4. Created: January 29, 1996 Updated: July 10, 1997 numer1.mcd Authors: Theresa Julia Zielinski and Danny G. Miles 6 -------------------------------------------------------------Now step through the algorithm. That is: i Implement the algorithm by computing X(t) for all values of i > 1. (Remember i = 0 was the first one. The default in Mathcad is zero as the start of all array subscripts.) X0 and X1 were assigned values in order to start the process. We can think of these as seed values for the algorithm. 2 , 3 .. n 2 2.X i Xi 1 2 Xi ∆ . . k Xi 12 2 10. k. X i The big equation here to the left is the differential equation solution algorithm. Compare this to equation 8 and show how this equation was constructed. 2 ∆ k. 12 1 k The parameter k is set as a global variable. Adjust the value of k here to the left and determine the value of k for which the curve equals X0 at the two ends of the range. 1.0 5 X i A preliminary graphical solution is shown here to the left. This solution clearly does not give the correct value for the amplitude at the two extremes of the period of oscillation that we chose at the beginning of the exercise. Adjust k until the function equals 4.0 at both ends of the range. Adjust the graph layout to show grid lines and the correct range that matches your differential equation. 0 5 1 0 2 4 t i 6 Questions: What is the range for this differential equation? Find values of k that give a graphical solution with zero, one, and two nodes. A graphical solution occurs when Xi = 4 at t equals 0 and at t equals the period of the oscillation. How does the value of k seem to vary for solutions that have different numbers of nodes? Created: January 29, 1996 Updated: July 10, 1997 numer1.mcd Authors: Theresa Julia Zielinski and Danny G. Miles 7 More Questions: 1. Choose several different periods of oscillation for the differential equation above. Graphically determine the k f period. By inspection or using graphical techniques determine the relationship between the period of oscillation force constant of the oscillator. 2. For the classical harmonic oscillator, rewrite the difference algorithm so that m, the mass of the oscillator, is ex included. For a fixed value of k, vary m systematically and determine how its value affects the graphical solutions inspection or using graphical techinques determine the relationship between the period of oscillation and the ma oscillator. VIII. Use of this method to solve graphically the Schroedinger differential equation for a simple harmonic oscilla This equation is of the form d2Ψ(x)/dx2 = f(x)Ψ(x). To use the numerical solution algorithm define f(x), write the appropriate form for equation 8 for this problem, set up a grid, establish low initial values for Ψ 0 and Ψ 1 and a range for the numerical solution. Proceed as outlined above. An energy guess must be made when using the algorithm. Try integer values for the energy until you have isolated a suitable solution. You have already deen the analytical solution for the harmonic oscillator case. Compare the graphs of the numerical solutions you obtain here with the Hermite polynomials. How do the energies obtained from the analytical solution compare to the energies you used in the numerical solution? Experiment with the value for the force constant and the boundary conditions for the solution of the problem. Determine how these affect the energy that permits a solution that satisfies these boundary conditions, i.e. the function is zero at the boundaries defined by the physics of the problem. Acknowledgement: Thanks to George Hargrove for constructive comments and assistance. 1. Bolemon, Jay S. Computer Solutions to a Realistic "One-Dimensional" Schroedinger Equation in volume 40, p 1511 (1972). 2. Rioux, Frank, Numerical Solutions for Schroedinger's Equation in "Enriching Quantum Chemistry with Mathcad" in Chem. Ed.:Software, volume 1D, number 2 (1994). 3. Rioux, Frank, Direct Numerical Integration of the Radial Equation in Am. J. of Physics volume 59, p 474 (1991). Created: January 29, 1996 Updated: July 10, 1997 numer1.mcd Authors: Theresa Julia Zielinski and Danny G. Miles 8