INTRODUCTION PHY37F/47F - Coputational Physics Background Material for Expt 3 - Heat Equation David Harrison In the Pendulu Experient, we studied the Runge-Kutta algorith for solving ordinary differential equations (ODEs) Here, we study techniques for solving partial differential equations (PDEs) The general proble of solving PDEs is huge; Press et al in Nuerical Recipes clai it requires an entire book However, there are soe siple cases Separation of Variables: Consider the Schrödinger equation: h / Ψ(x,t) x +V(x)Ψ(x,t)ih Ψ(x,t) t () If we assue that the wavefunction can be written as a function of position ties a function of tie: then: Ψ(x,t) ψ(x)φ(t) h d / ψ(x) ψ(x) dx +V(x)ψ(x) ih φ(t) dφ c () dt where c is a constant Thus we have turned the proble into two ordinary differential equations First order PDEs: If the equations are linear, then a closed solution can easily be found If the equations are non-linear, a faily of paraetric solutions can be found The standard Matheatica package Calculus PDSolve handles this latter case Second order PDEs: There are two general classes of these: Poisson, soeties called "elliptic" 7
-- Cauchy, soeties called "initial value" The Poisson equation is, of course: u u + x y ρ(x,t) (3) This type of equation turns out to be very easy to solve using a technique called a relaxation ethod The Cauchy class of second order PDEs is subdivided further: i The wave equation (a hyperbolic for): ii u v u t x The heat equation (a parabolic for): (4) u u c (5) t x x For both of these, you will discover that stability is a proble: any reasonable looking algoriths just don t work unless care is taken In this Experient, we will concentrate on the heat equation Usually, u is the teperature We will assue that we are solving the equation for a one diensional slab of width L We will usually assue that c is a constant so the heat equation becoes: u(x,t) u(x,t) c t x We will adopt units where x/l x and tc/l t, so the heat equation is now: u(x,t) u(x,t) t x x These notes are organised as follows: I Explicit algorith II III Iplicit algorith Crank-Nicholson algorith (6)
-3- IV Schrödinger s equation V References Note that the "usual" code listing is not included in this docuent That is because you will be odifying soe of the code to produce a new procedure, and cutting and pasting the code within the notebook is the siplest way to do this Thus, the code listing appears in the notebook instead of these suppleentary notes for the Experient I EXPLICIT ALGORITHM We iagine that we divide our one diensional slab into n interior points, and will call the distance between each point x We will step through tiesteps We will be using the notation that: u j u(x j j x,t ) j n+ (n+) x,,, (I) (tie ) 4 3 3 4 5 6 n- n- n n+ j (position j x) We will write the initial condition as: u j g (x) (I) and the boundary conditions as: u α β u n+ It is reasonable to write the left hand side of the heat equation, Equation (6), as: (I3a) (I3b)
-4- u u + j u j t We write the right hand side of Equation (6) as: u x xj u x xj + u x xj (I4) / x (I5) Note that we write u/ x evaluated at two points that are not on our grid This doesn t atter because: Thus, Equation (I5) becoes: u x xj + u x xj u(x,t) x xj u j+ x u j u j u j x x u j+ u j +u j (I6) The above way of solving the second-order partial derivative is called the ethod of finite differences so: The heat equation states that Equation (I4) equals Equation (I6): u j + u j x u j+ u j +u j (I7) u + j u j + x u j+ u j +u j (I8) Note that the right hand side of Equation (I8) contains values of u at tie t, and these ters are cobined to give the value of u at the later tie t + (+) Once the values of u at tie t + (+) are known we can then find the values at t + (+), and so on Thus we can solve the heat equation for all values of t using this explicit algorith The deterination of u j + depends on knowing the values of u at three positions at the earlier tie:
-5- + j- j j+ Note that this schee does not allow one to deterine u + because we have no values for u But that does not atter: u + is the value of u at the left side of the slab, and is given by the boundary condition Equation (I3a) Siilarly the boundary condition Equation (I3b) gives the value for u + n+ So Equation (I8) is used only to evaluate the interior values of u + The above way of solving the heat equation is pretty siple Of the three algoriths you will investigate to solve the heat equation, this one is also the fastest and also can give the ost accurate result However, the result will be accurate only if you choose tiesteps and a space grid size x such that: ( x) µ Solutions produced in violation of Equation (I9) will be unstable, often producing ridiculous results Note that this eans that for a given tiestep the space grid size x can not be too sall For a given space grid size, the tiestep can not be too big We will discuss later in this docuent the fact that even if the tiestep and space grid satisfy Equation (I9), the explicit algorith can still produce wrong results for soe physical systes The reasons for the instability of the explicit algorith is soewhat beyond the level of this course; consult the references for further inforation However, we can justify Equation (I9) (I9) Golub and Ortega, 8
-6- The heat equation also governs the diffusion of, say, a sall quantity of perfue in the air You probably already know that diffusion is a for of rando walk so after a tie t we expect the perfue has diffused a distance x t One solution to the heat equation gives the density of the gas as a function of position and tie: u (x,t) ρ(x,t) e x σ σ (I) where: σ ct and c is the heat constant defined in Equation (5), for which we usually have been choosing units so that it equals In a diffusion context c is often called the diffusion constant Equation (I) shows that the density of the diffusing gas is a Gaussian, and that the standard deviation describing the width of the Gaussian increases as the square root of t This eans that in a tie, the olecules travel a distance x on the order of: x c Thus, if we are solving the equations using an explicit algorith, for a given : x (I) since otherwise the distribution is not spreading as fast as we know it should A trivial rearrangeent of Equation (I) gives: which is just Equation (I9) II IMPLICIT ALGORITHM ( x) Consider the following equation and copare it to Equation (I7) fro the previous section: u + u j ( x) (u + j+ u + j +u + j ) (II) Here we are evaluating u/ x using finite differences at tie t + instead of t A oent s reflection should convince you that Equation (II) is just as reasonable as Equation (I7) We rearrange Equation (II):
-7- (+µ)u + j µ(u + j+ +u + j ) u j (II) where recall that: µ ( x) Thus we are trying to find u at ties + at three different positions j-, j and j+ fro a single value of u at the earlier tie + j- j j+ At first glance, this is ipossible However, consider an (n+) (n+) identity atrix Id: Id an (n+) (n+) (,-) triangular atrix A: A and an n+ diensional colun atrix b :
-8- b µα µβ Then the entire set of equations for all values of j given by Equation (II) can be written as: (Id + µa)u + u +b (II3) where: u u u u u n u n+ If we know u, the values of u at tie, Equation (II3) ay be solved for u + using, for exaple, the LU decoposition that you studied in the Exercise The above technique for solving the heat equation is called an iplicit algorith You will discover in the Experient that this algorith is stable for all values of µ That is the good news There is also soe bad news: the iplicit technique is uch slower than the explicit one and is also uch less accurate for a given value of tiestep and space grid size x III CRANK-NICHOLSON ALGORITHM The explicit algorith begins with: u + u j ( x) (u j+ u j +u j ) while the iplicit one begins with: u + u j ( x) (u + j+ u + j +u + j ) Average these two equations:
-9- u + u j ( x) (u j+ u j +u j +u + j+ u + j +u + j )) (III) In ters of the atrices defined in the previous section, we can write Equation (III) as: µ (Id + A)u + µ (Id A)u +b (III) This equation is, of course, solvable using LU decoposition We are finding the values of u + j, u + j and u + j+ fro the values of u j,u j and u j+ + j- j j+ The above is the Crank-Nicholson algorith You will discover that it aintains the absolute stability of the iplicit algorith while recovering soe of the accuracy of the explicit one IV SCHRÖDINGER S EQUATION Assuing h and /, Schrödinger s equation is: i Ψ(x,t) HΨ(x,t) t H +V(x) x (IV) In the late 96 s, Goldberg, Schey and Schwartz had a good idea for a lecture deonstration in quantu echanics 3 They decided to solve this equation using thennew coputer technology to produce a ovie The initial conditions for Equation (IV) are 3 Goldberg, Schey and Schwartz, Aer Jour Phys 35, (967) 77
-- Ψ(x,)g(x) and the boundary conditions are: Ψ(,t) Ψ(,t) The solution to Equation (IV) can be written as: Ψ(x,t) e iht Ψ(x, ) (IV) Expand Equation (IV) and throw out higher order ters: Ψ(x,t + ) ( iht)ψ(x,t) (IV3) Thus if we know Ψ(x,t) we can produce a tie series of values for Ψ at ties t+, t+, Using finite differences to evaluate the / x ter in the Hailtonian H, the right hand side of Equation (IV3) will give a ter involving (Ψ j Ψ j +Ψ j+ ) This should be recognisable to you as an explicit algorith We can ultiply Equation (IV) by e iht and expand to get: ( + iht)ψ(x,t + ) Ψ(x,t) (IV4) Now evaluating the Hailtonian using finite differences will give a ter involving (Ψ + j Ψ + j +Ψ + j+ ) on the left hand side This is, of course, just an iplicit algorith Everything we have said about explicit and iplicit algoriths applies to these cases too However, the physics of Quantu Mechanics puts an additional constraint on Ψ: x Ψ * (x,t)ψ(x,t)dx for all ties t This is called unitarity and physically eans that the probability that the object being described by the wave function is soewhere between x and x is one It has been known since long before the invention of the coputer that Equations (IV3) and (IV4) violate unitarity This eans that neither the explicit or iplicit algorith can be used to solve Schrödinger s equation because they both violate a physical principle A long-known equation that does not violate unitarity is called Cayley s for Multiply Equation (IV) by e iht/ and expand both sides: (IV5)
-- ( + i Ht)Ψ(x,t +)( i Ht)Ψ(x,t) (IV6) Using finite differences to evaluate the / x ters in the Hailtonian on both sides of the equation will give us a Crank-Nicholson algorith The lesson to be learned here is that just knowing the nuerical ethods is soeties not sufficient Just as for the pendulu, where the physics pointed us to the syplectic algorith, here the physics points us to a Crank-Nicholson algorith when solving Schrödinger s equation V REFERENCES Gene H Golub and Jaes M Ortega, Scientific Coputing and Differential Equations (Acadeic Press, 99), Chapter 7 Willia H Press, Brian P Flannery, Saul A Teukolsky, and Willia T Vetterling, Nuerical Recipes: The Art of Scientific Coputing or Nuerical Recipes in C: The Art of Scientific Coputing (Cabridge Univ Press), Chapter 7 Exaples of solving Poisson s equation using relaxation ethods, and a visualisation of Schrödinger s equation solved using a Crank-Nicholson algorith ay be found at: http://eeraldathbuffaloedu/ ringland/instruction/pde/ Copyright 998 David M Harrison This is version, date (/d/y) /8/98