Introduction to . . . Partial Differential Equations The Laplace’s Equation Peter Coutts & Jerad Meisner Harmonic Functions Spherical Harmonic . . . May 18, 2015 Mathematica Code

Home Page Abstract Title Page Partial differential equations appear frequently in the study of physical phenomena including sound, heat, fluid dynamics, and elec- JJ II trostatics and also play a central roll in the study of quantum me- chanics. This paper will examine several partial differential equa- J I tions (PDEs) and how they apply to the real word. It will detail one method for solving PDEs known as and take Page1 of 45 a brief look at what some of these solutions mean.

Go Back

Full Screen

Close

Quit 1. Introduction to Partial Differential Equa- tions Introduction to . . . A partial differential equation (PDE) is any differential equation that con- The Heat Equation tains unknown multivariable functions and their partial . They Laplace’s Equation are commonly used to model the rates of change of physical quantities with Harmonic Functions respect to both space and time. Some examples are: the Spherical Harmonic . . .

2 Mathematica Code ∂ u 2 2 2 = c ∇ u ∂t Home Page for modeling sound, light, and water waves; the Euler-Tricomi equation Title Page ∂2u ∂2u = x ∂x2 ∂y2 JJ II for studying transonic flows; and the Schr¨odingerequation J I ∂ i Ψ = Hˆ Ψ Page2 of 45 ~∂t for describing how the of a physical system changes with Go Back respect to time. While many PDEs exist for describing a wide variety of Full Screen physical phenomena we will be focusing on two specific equations in this paper. Close

Quit 2. The Heat Equation

The one-dimensional heat equation Introduction to . . . ∂u ∂2u The Heat Equation = k (1) ∂t ∂x2 Laplace’s Equation Harmonic Functions describes the temperature distribution in an object. The solution, u(x, t), Spherical Harmonic . . . represents the temperature at a given point x at time t, and k > 0 is a Mathematica Code constant value called the thermal conductivity and measures the ability of the object in question to conduct heat. Home Page

Title Page 2.1. Method of Separation of Variables Many PDEs, including the heat equation, can be solved using a technique JJ II known as the method of separation of variables. We will use the one- dimensional heat equation as a simple example to explain how to perform J I separation of variables so that we may use it later to solve a more difficult Page3 of 45 equation.

Go Back 2.1.1. General Solution Full Screen When using the method of separation of variables, we begin by making the assumption that our solution (in this case u(x, t)) is actually a product Close solution – a product of functions, each of which is dependent upon a single

Quit variable [6]. In the case of the heat equation, we make the assumption that our solution will be of the form

Introduction to . . . u(x, t) = F (x)G(t). The Heat Equation The reason for this, is that it will turn the PDE into two ordinary differential Laplace’s Equation equations (ODEs) which should be much easier to solve. Now that we have Harmonic Functions defined the form for our final solution, we can plug it into equation (1) and Spherical Harmonic . . . differentiate Mathematica Code ∂ ∂2 [F (x)G(t)] = k [F (x)G(t)] ∂t ∂x2 Home Page

dG d2F Title Page F (x) = kG(t) . dt dx2 JJ II In the step above, we factored out F (x) from the partial on the left hand side (LHS), and G(t) from partial derivative on the right J I hand side (RHS), since they are not dependent upon the variable we are differentiating with respect to. Since we are then only differentiating single Page4 of 45 variable functions, we no longer have any partial derivatives to worry about. Now we need to move all expressions involving t to one side of the equation, Go Back and all expressions involving x to the other side. To do this we just divide both sides of the equation by F Gk and we are left with Full Screen 1 dG 1 d2F = . (2) Close kG dt F dx2

Quit Now, since we are dealing with an equation, we know that the left side and right side must be equal. We also know that in order for this equation to be true, both the LHS and RHS must be equal to a constant. If this were not Introduction to . . . the case, when we varied either t or x, only one side of the equation would The Heat Equation change and the equation would no longer be true. With this information in Laplace’s Equation mind, we will let γ be a constant value known as the separation constant, Harmonic Functions and rewrite equation (2) as two equations Spherical Harmonic . . . 1 dG 1 d2F Mathematica Code = γ = γ kG dt F dx2 (3) Home Page dG d2F = γkG = γF (4) Title Page dt dx2 We now have two linear ODEs that we can solve using standard techniques. JJ II

J I 2.1.2. Particular Solution with Initial and Boundary Conditions In order to find a particular solution we need to first understand the sit- Page5 of 45 uation we are modeling. In the case of the one-dimensional heat equation we can think of this as a thin bar of material on the x-axis and u(x, t) will Go Back represent the temperature of a cross-section of the material at position x at Full Screen time t (see Figure1)[6].

Close

Quit Introduction to . . . The Heat Equation Laplace’s Equation Harmonic Functions Spherical Harmonic . . . Figure 1: One-dimensional heat equation Mathematica Code

Home Page Now let’s define some initial and boundary conditions so that we may find a particular solution Title Page k = 2, 0 ≤ x ≤ π, t > 0 (5) JJ II u(0, t) = 0, u(π, t) = 0 (6) u(x, 0) = x, 0 ≤ x ≤ π. (7) J I

Here, in Equation (5) we are defining the thermal conductivity of the object Page6 of 45 to be 2, and defining the domain of our function. In Equation (6) we are stating that the temperature at the boundaries is 0 at all t. Equation (7) is Go Back our initial condition and states that, at t = 0, the temperature at any given cross-section is equal to the x position of the cross-section [6]. We will now Full Screen rewrite our linear ODEs from Equation (4) using prime notation and the k Close

Quit value we chose F 00 − γF = 0 (8) G0 − 2γG = 0. (9) Introduction to . . . The Heat Equation Now we can begin to solve these ODEs to satisfy our boundary conditions. Laplace’s Equation We will start with Equation (8) and we are only looking for non-trivial Harmonic Functions solutions. To do this we need to recognize that we have three possibilities Spherical Harmonic . . . for γ that we will have to examine: γ = 0, γ < 0, and γ > 0, so we will need Mathematica Code to solve three times: once for each possibility. We will begin with γ = 0 and Equation (8) becomes Home Page F 00 = 0. Title Page Integrating twice yields F (x) = Ax + B. (10) JJ II

Now, our boundary conditions from Equation (6) give: J I u(0, t) = u(π, t) = 0. Page7 of 45 Since u(x, t) = F (x)G(t) our boundary conditions will be satisfied if Go Back

F (0) = F (π) = 0 Full Screen or G(t) = 0, for all t, Close

Quit but since the latter will give us the trivial solution for all t, we are only in- terested in the former. Now, we can see here that, to satisfy these boundary conditions, both A and B must be 0. If we plug these values into Equa- Introduction to . . . tion (10) this will yield the trivial solution to our original PDE, so we will The Heat Equation ignore it. Still using Equation (8), we can now examine the situation where Laplace’s Equation γ > 0. In this case we can find eigenvalues using the characteristic equation: Harmonic Functions λ2 − γ = 0 Spherical Harmonic . . . √ λ = ± γ. Mathematica Code

Since we have distinct real roots, we know that our solution will be a linear Home Page combination of exponentials of the eigenvalues Title Page √ √ F (x) = Ae γx + Be− γx. (11) JJ II Now we will use our boundary conditions to solve for A and B. We will start with F (0) = 0 J I

F (0) = 0 Page8 of 45 Ae0 + Be0 = 0 Go Back A + B = 0.

Full Screen We can see here that A = −B. Now we will use our second boundary condition, but this time, armed with this new knowledge, we will substitute Close

Quit −A in for B

F (π) = 0 √ √ Introduction to . . . γπ − γπ Ae − Ae = 0 The Heat Equation √ √ γπ − γπ A[e − e ] = 0. Laplace’s Equation Harmonic Functions Here we can see that A must equal 0 to satisfy this equation, therefore, since Spherical Harmonic . . . A = −B, B is also equal to 0. If we plug these values into Equation (11), Mathematica Code we see that F (x) = 0 for all x, so, again, we have the trivial solution, and this situation is also of no interest to us. So lets examine the final case Home Page where γ < 0, but first we are going to let γ = −ρ2. This is done to simplify our characteristic equation and eliminate unnecessary square roots, so our Title Page characteristic equation for Equation (8) becomes JJ II λ2 + ρ2 = 0 λ2 = −ρ2 J I λ = ±ρi. Page9 of 45 Here we have distinct complex roots, so our solution will have the form Go Back F (x) = A cos ρx + B sin ρx. Full Screen We can now evaluate our boundary conditions and once again we will begin Close

Quit with F (0) = 0 F (0) = 0 A cos 0 + B sin 0 = 0 Introduction to . . . The Heat Equation A = 0. Laplace’s Equation Harmonic Functions Now we will use F (π) = 0, letting A = 0 Spherical Harmonic . . . Mathematica Code F (π) = 0 B sin ρπ = 0 Home Page

This equation could be satisfied if B = 0, but that would give us the trivial Title Page solution, therefore sin (ρπ) must equal 0, and this is true for ρ ∈ N so we have infinitely many solutions. We will denote with n, thus ρπ = nπ so N JJ II ρ = n, and our solution will be a sequence of sin nπ. J I Now that we have all of our solutions of Equation (8), we can begin solving Equation (9). Once again we will have to consider situations for different Page 10 of 45 γ values, but since we know that γ = 0 and γ > 0 both give us the trivial solution, we will only focus on the case where γ < 0 Go Back

0 G − 2γG = 0 Full Screen G0 = 2γG G = Ce2γt. Close

Quit Using our previous definitions of ρ and n, we get G = Ce−2ρ2t = Ce−2n2t Introduction to . . . The Heat Equation so, once again, our solution will be a sequence. Laplace’s Equation Harmonic Functions Now that we have solutions to our ODEs, we can plug them into into our Spherical Harmonic . . . original solution Mathematica Code u(x, t) = Fn(x)Gn(t) −2n2t Home Page = an sin (nx)e .

Here the n subscripts indicate that this is a sequence for n = 1, 2, 3, ... and Title Page an is the product of the two arbitrary coefficients (B and C) we found earlier. Since our original PDE is linear and homogeneous, we know that any linear JJ II combination of solutions is also a solution, so we can now write our solution as a series [6] J I ∞ 2 X −2n t Page 11 of 45 u(x, t) = an sin (nx)e . (12) n=1 The last thing left to do is use our initial condition from Equation (7) to Go Back solve for the coefficients an. Plugging in t = 0 we get Full Screen ∞ X u(x, 0) = a sin (nx). n Close n=1

Quit This series is known as a – namely a Fourier sine series – and we can solve for our coefficients using the formula [6]

L Introduction to . . . Z 2 nπx The Heat Equation an = f(x) sin dx L L Laplace’s Equation 0 π Harmonic Functions 2 Z = x sin nx dx Spherical Harmonic . . . π Mathematica Code 0 where L is the length of the material. Using integration by parts we will Home Page find [5] Title Page 2 a = (−1)n+1. n n JJ II Substituting this expression for our coefficients back into Equation (12) we get our final solution J I

∞ X 2 2 Page 12 of 45 u(x, t) = (−1)n+1 sin (nx)e−2n t n n=1 Go Back

Full Screen Figure (2) is the graphical representation of this solution and shows how the heat distribution changes over time. The Mathematica code used to create Close this plot is available in Appendix A.

Quit Introduction to . . . The Heat Equation Laplace’s Equation Harmonic Functions Spherical Harmonic . . . Mathematica Code

Home Page

Title Page

JJ II

J I

Page 13 of 45

Figure 2: Heat equation solution Go Back

Full Screen

Close

Quit 3. Laplace’s Equation

Laplace’s equation is a second-order, homogeneous, PDE of a function f. In Introduction to . . . cartesian coordinates f is a function of x, y, and z and Laplace’s equation has the form [7] The Heat Equation Laplace’s Equation ∂2f ∂2f ∂2f Harmonic Functions ∇2f = + + = 0 (13) ∂x2 ∂y2 ∂z2 Spherical Harmonic . . . Mathematica Code where ∇2 is known as the Laplacian operator. Laplace’s equation has many applications in physics and engineering such as calculating gravitational and Home Page electro-static potentials, steady-state heat distribution, velocity potentials in fluid dynamics, and many other problems involving transport phenomena. Title Page For example, to calculate electric potential the electric field is related to the charge density by [3] JJ II ρ ∇ · E = , J I ε0 Page 14 of 45 where E is the electric field, ρ is the charge density, and ε0 is a permittivity constant known as vacuum permittivity which is approximately 8.85×10−12 farads/meter. The electric field is related to the electric potential by [3] Go Back

E = −∇V. Full Screen

Then the potential relates to the charge density by [3] Close

Quit ρ ∇ · ∇V = − . ε0 Here, the divergence of the gradient can be written as Introduction to . . . The Heat Equation Laplace’s Equation ∂ ∂V  ∂ ∂V  ∂ ∂V  ρ + + = − Harmonic Functions ∂x ∂x ∂y ∂y ∂z ∂z ε0 Spherical Harmonic . . . Mathematica Code ∂2V ∂2V ∂2V ρ Home Page 2 + 2 + 2 = − . ∂x ∂y ∂z ε0 This is known as Poisson’s equation, and is the non-homogeneous version Title Page of Laplace’s equation. Therefore, in a charge-free region of space (where ρ = 0), Poisson’s equation simplifies to Laplace’s equation JJ II

∂2V ∂2V ∂2V J I + + = 0, ∂x2 ∂y2 ∂z2 Page 15 of 45 which is commonly denoted as

Go Back ∇2V = 0. The Laplacian, ∇2, is shorthand for the divergence of the gradient, which Full Screen Laplace’s equation imposes must be equal to 0. Close

Quit 3.1. Solving Laplace’s Equation Laplace’s equation, just like the heat equation, is solved using separation of variables regardless of the coordinates used and the solutions are called Introduction to . . . harmonic functions [2,3]. We are going to examine the solution to Laplace’s The Heat Equation equation in polar spherical coordinates in depth later so we need to solve Laplace’s Equation in spherical coordinates now where f is a function of ρ, θ, and φ. We will Harmonic Functions transform to spherical coordinates by defining Spherical Harmonic . . . Mathematica Code

x = ρ sin θ cos φ Home Page y = ρ sin θ sin φ z = ρ cos θ, Title Page where ρ, θ, and φ are the radial distance, polar angle, and azimuthal angle JJ II respectively. By calculating the partials and substituting them into equa- tion (13) we can transform Laplace’s equation from cartesian coordinates J I

∂2f ∂2f ∂2f Page 16 of 45 + + = 0 ∂x2 ∂y2 ∂z2 Go Back to spherical coordinates Full Screen 1 ∂  ∂f  1 ∂  ∂f  1 ∂2f ρ2 + sin θ + = 0. (14) ρ2 ∂ρ ∂ρ ρ2 sin θ ∂θ ∂θ ρ2 sin2 θ ∂φ2 Close

Quit To solve equation (14) using separation of variables, just like we did with the heat equation, we will first recognize that our solution should be the prod- uct of three functions, each of which is dependent on a single independent Introduction to . . . variable, so our solution should have the following form [2,5] The Heat Equation Laplace’s Equation f(ρ, θ, φ) = R(ρ)Θ(θ)Φ(φ). (15) Harmonic Functions Spherical Harmonic . . . With this knowledge in mind, we can calculate the partial derivatives of this Mathematica Code function Home Page

∂f dR ∂f dΘ ∂2f d2Φ = ΘΦ = RΦ = Rθ Title Page ∂ρ dρ ∂θ dθ ∂φ2 dφ2 JJ II and replace them into equation (14)

ΘΦ ∂  dR RΦ ∂  dΘ RΘ d2Φ J I ρ2 + sin θ + = 0. 2 2 2 2 2 ρ ∂ρ dρ ρ sin θ ∂θ dθ ρ sin θ dφ Page 17 of 45

Go Back At this point we can start separating variables by multiplying both sides of our equation by ρ2 sin2 θ/RΘΦ. We will also change the partial derivatives Full Screen to standard derivatives since we now know that each function in our solution is dependent on a single variable [2,5] Close

Quit sin2 θ d  dR sin θ d  dΘ 1 d2Φ ρ2 + sin θ + = 0. (16) R dρ dρ Θ dθ dθ Φ dφ2 Introduction to . . . | {z } | {z } The Heat Equation g(ρ,θ) h(φ) Laplace’s Equation In cartesian coordinates, this would have been all we needed to do to sepa- Harmonic Functions rate variables. In spherical coordinates, however, we need a few more steps Spherical Harmonic . . . since the first term contains both ρ and θ. We begin by identifying a couple Mathematica Code distinct parts of the equation, the part containing ρ and θ, which we will define as g(ρ, θ), and the part that only contains φ, which we will define as Home Page h(φ). We can also see that in order for this equation to be satisfied, g(ρ, θ) must be equal to −h(φ). This means that both functions must be constant Title Page for the same reason we covered during our discussion of the heat equation. This time, since h(φ) contains a second derivative we will let this constant JJ II be m2. We can now focus on h and we will be using prime notation here for the sake of simplicity J I

Page 18 of 45 h(φ) = −m2 1 Φ00 = −m2 Go Back φ 00 2 Φ = −m φ Full Screen Φ00 + m2φ = 0. Close

Quit Now we can solve using the characteristic equation λ2 + m2 = 0 Introduction to . . . λ2 = −m2 The Heat Equation λ = ±mı. Laplace’s Equation Our characteristic equation has distinct complex roots so we know that Φ(φ) Harmonic Functions will have the form Spherical Harmonic . . . Mathematica Code Φ(φ) = C cos mφ + D sin mφ.

Home Page Since we know that φ is the azimuthal angle on a , we know that Φ must be periodic on 2π. This makes intuitive sense since if we travel Title Page through an angle of 2π around the equator of a sphere we will be back where we started. Therefore we know that m is necessarily an integer due JJ II to this periodicity constraint. We can now plug this back into equation (16). 2 We will also finish separating variables by dividing by a factor of sin θ J I

1 d  dR 1 1 d  dΘ m2 Page 19 of 45 ρ2 + sin θ − = 0. (17) R dρ dρ Θ sin θ dθ dθ sin2 θ | {z } | {z } Go Back G(ρ) H(θ)

Full Screen Now that we have separated our variables, we will define G(ρ) and H(θ) and then observe that, in order for our equation to be satisfied, G(ρ) must Close equal −H(θ) so we will let

Quit G(ρ) = `(` + 1), Introduction to . . . H(θ) = −`(` + 1). The Heat Equation We make this choice in hindsight, knowing the form our final solution must Laplace’s Equation take [5]. We could have used arbitrary placeholders like k and −k, but we Harmonic Functions would have ended up going back and making this correction anyway. We can Spherical Harmonic . . . now solve for R(ρ) and Θ(θ) by equating these expressions to the functions Mathematica Code we defined. We will begin with G(ρ) and once again we will switch to prime notation Home Page

1 Title Page (ρ2R0)0 = `(` + 1) R 2 0 0 (ρ R ) = `(` + 1)R JJ II ρ2R00 + 2ρR0 = `(` + 1)R J I ρ2R00 + 2ρR0 − `(` + 1)R = 0. (18)

Page 20 of 45 Notice in Equation (18) that every time R is differentiated, it is also multi- plied by ρ. This special form is known as Euler’s equation and solving it is Go Back pretty straight forward once we recognize that the solution will be a power s function of the form R(ρ) = ρ . This should become clear by taking the Full Screen

Close

Quit first two derivatives, multiplying the derivative by ρ each time

R(ρ) = ρs Introduction to . . . 0 s ρR (ρ) = sρ The Heat Equation 2 00 s ρ R (ρ) = s(s − 1)ρ . Laplace’s Equation Harmonic Functions Making these substitutions we get Spherical Harmonic . . . ρ2R00 + 2ρR0 − `(` + 1)R = 0 Mathematica Code s [s(s − 1) + 2s − `(` + 1)]ρ = 0 Home Page [s2 − s + 2s − `(` + 1)]ρs = 0 [s2 + s − `(` + 1)]ρs = 0. Title Page

s If ρ = 0 then ρ = 0, R(ρ) = 0 for all ρ, and we are left with the trivial JJ II solution, so we are only interested in the situation where s2 +s−`(`+1) = 0. J I

Page 21 of 45

Go Back

Full Screen

Close

Quit We solve this using the quadratic formula

−1 ± p1 + 4(`2 + `) s = Introduction to . . . 2 √ The Heat Equation −1 ± 4`2 + 4` + 1 = Laplace’s Equation 2 Harmonic Functions −1 ± p(2` + 1)2 = Spherical Harmonic . . . 2 Mathematica Code −1 ± (2` + 1) = 2 Home Page 2` −2` − 2 = , 2 2 Title Page = `, −(` + 1). JJ II Therefore, our solutions are ρ` and ρ−(`+1) and since these solutions are lin- early independent, any is also a solution so our complete J I solution becomes Page 22 of 45 R(ρ) = Aρ` + Bρ−(`+1). Go Back Now we have found solutions for two of the functions in our product solution Full Screen

Close

Quit so all that is left to do is solve H(θ) that we defined in Equation (17)

1 1 d  dΘ m2 sin θ − = −`(` + 1) Introduction to . . . Θ sin θ dθ dθ sin2 θ The Heat Equation 1 d  dΘ m2 sin θ − Θ = −`(` + 1)Θ. (19) Laplace’s Equation sin θ dθ dθ 2 sin θ Harmonic Functions Now, we need to use a change of variables to get this equation into a form Spherical Harmonic . . . we can deal with. We will use the following transformation as it will allow Mathematica Code us to eliminate some of the in our equation and also allow us to use trig identities to further simplify things: Home Page

x = cos θ Title Page

JJ II dx = − sin θ dθ J I

dΘ dΘ dx Page 23 of 45 = dθ dx dθ dΘ Go Back = − sin θ . dx Full Screen

Close

Quit So Equation (19) becomes

  2 1 d 2 dΘ m (− sin θ) − sin θ − Θ = −`(` + 1)Θ Introduction to . . . sin θ dx dx sin2 θ The Heat Equation d  dΘ  m2  − −(1 − cos2 θ) + `(` + 1) − Θ = 0 Laplace’s Equation dx dx (1 − cos2 θ) Harmonic Functions    2  d 2 dΘ m Spherical Harmonic . . . (1 − x ) + `(` + 1) − 2 Θ = 0. dx dx 1 − x Mathematica Code

Now our equation is more manageable so we will switch to prime notation Home Page and differentiate  m2  Title Page (1 − x2)Θ00 + `(` + 1) − Θ = 0 1 − x2  2  JJ II 2 00 0 m (1 − x )Θ − 2xΘ + `(` + 1) − 2 Θ = 0. 1 − x J I

While this may not seem much better, it is actually a special second-order Page 24 of 45 differential equation called Legendre’s equation. While solving this equation is beyond the scope of this paper, the solution is a set of functions known as Go Back associated [4] which we will take a closer look at later, but for now we just need to know that the notation for these polynomials is Full Screen

m Θ(x) = P` (x). Close

Quit Switching back to θ this becomes

Θ(θ) = P m(cos θ). ` Introduction to . . . Now that we have solved all three functions we can write our general solution The Heat Equation in the form we outlined in equation (15) Laplace’s Equation Harmonic Functions Spherical Harmonic . . . ∞ `   X X B`,m Mathematica Code f(ρ, θ, φ) = A ρ` + P m(cos θ) (C cos mφ + D sin mφ) . `,m ρ(`+1) ` `,m `,m `=0 m=0 | {z } | {z } | {z } Θ(θ) Φ(φ) Home Page R(ρ)

A, B, C, and D are arbitrary constants that are solved for using given initial Title Page and boundary conditions. JJ II

4. Harmonic Functions J I

As mentioned earlier, the solutions of Laplace’s equation are called harmonic Page 25 of 45 functions and we are now going to take a closer look at the important roll they play in a wide variety of disciplines. For the purposes of this paper, Go Back we will ignore the spacial (ρ dependent) part of the solution and focus on the angular (θ and φ dependent) part. Full Screen

Close

Quit 4.1. Associated Legendre Polynomials We will begin with the θ dependent part which, as we mentioned earlier, is a set of functions called associated Legendre polynomials. The associated Introduction to . . . Legendre polynomials are a class of recursively named The Heat Equation for french mathematician Adrien-Marie Legendre and it is important to Laplace’s Equation understand them since they will appear explicitly in our definition of spher- Harmonic Functions ical harmonics later [2,1]. These functions are a complete orthogonal set Spherical Harmonic . . . of solutions to Legendre’s equation which obey the following Mathematica Code relationship over their domain [a, b]: Home Page b Z w(x)Pn(x)Pm(x)dx = cnδnm Title Page a JJ II where w(x) is an arbitrary weighting function, cn is a constant, and δnm is the , defined by J I ( 1 n = m Page 26 of 45 δnm = 0 n 6= m. Go Back In other words, if you integrate the product of two of the functions in the set over their entire domain, the result will be zero if the functions are different Full Screen or a constant if they are the same [1]. The associated Legendre polynomials Close

Quit are defined as m `+m m (−1) p 2 m d 2 ` P` (x) = ` (1 − x ) `+m (x − 1) 2 `! dx Introduction to . . . over the domain [−1, 1] with ` ∈ N0 and m ∈ [0, `]. This definition, however, The Heat Equation is typically not used in computations because it is numerically unstable. Laplace’s Equation For computation purposes, especially when using a computer, the following Harmonic Functions recurrence relationships are generally used since they are more stable and Spherical Harmonic . . . easier to implement in a computer program [2] Mathematica Code m m 2 m/2 Pm (x) = (−1) (2m − 1)!!(1 − x ) m m Home Page Pm+1(x) = x(2m + 1)Pm (x) m m m (` − m)P` (x) = x(2` − 1)P`−1(x) − (` + m − 1)P`−2(x). Title Page The first five associated Legendre polynomials are listed below and Fig- ure (3) shows a plot of these five functions. The Mathematica code used to JJ II generate the plot is available in appendix A. J I 0 P0 (x) = 1 Page 27 of 45 P 0(x) = x 1 √ 1 2 Go Back P1 (x) = − 1 − x

0 1 2 Full Screen P2 (x) = (−1 + 3x ) 2 √ 1 2 P2 (x) = −3x 1 − x . Close

Quit Introduction to . . . The Heat Equation Laplace’s Equation Harmonic Functions Spherical Harmonic . . . Mathematica Code

Home Page

Title Page

JJ II

J I

Page 28 of 45 Figure 3: First five associated Legendre polynomials, y(0) = 1 Go Back

Full Screen

Close

Quit 4.1.1. Function Expansion/Reconstruction Because of their orthogonality, associated Legendre polynomials are what is known as basis functions and this is where their real power lies. They form a Introduction to . . . basis for the function space in which they lie and every piecewise continuous The Heat Equation function in the same space can be represented as a linear combination of Laplace’s Equation associated Legendre polynomials. To reconstruct a function f(x) using the Harmonic Functions associated Legendre polynomials, we first calculate coefficients an for each Spherical Harmonic . . . of the functions by [1] Mathematica Code

1 Z Home Page an = f(x)Pn(x)dx. −1 Title Page

This basically tells us how much each function is similar to f(x). We then JJ II create our linear combination by [1] J I N X f(x) ≈ anPn Page 29 of 45 n=0 and the higher we take N, the closer our approximation will be. If we take Go Back N = ∞ we can match any function exactly. Figure (4) show an example Full Screen of a function expansion using the associated Legendre polynomials. The mathematica code used to generate this figure is available in appendix A. Close

Quit Introduction to . . . The Heat Equation Laplace’s Equation Harmonic Functions Spherical Harmonic . . . Mathematica Code

Home Page

Title Page

JJ II

J I

Page 30 of 45

Go Back Figure 4: Legendre expansion of f(x) = −1.2x6 +3.1x5 −2.1x4 +6x3 −3x2 +2x−2 Full Screen

Close

Quit 4.2. Spherical Harmonics Spherical Harmonics are the entire angular (θ and φ dependent) part of the solution to Laplace’s equation in polar spherical coordinates [2] and are Introduction to . . . denoted by The Heat Equation Laplace’s Equation Harmonic Functions m m imφ Y` (θ, φ) = P` (cos θ)e Spherical Harmonic . . . Mathematica Code where ` ∈ N0 and −` ≤ m ≤ `. Spherical Harmonics play an important role in many scientific and engineering applications. In physics, they are used to Home Page calculate electron orbitals, represent gravitational and magnetic fields, and characterize cosmic microwave background radiation. They are also used Title Page in computer graphics applications to calculate lighting and model three- dimensional shapes [7]. Like the associated Legendre polynomials, spherical JJ II harmonics also form an orthogonal set and obey a similar orthogonality relationship [1] J I ZZ Page 31 of 45 w(θ, φ)Yn(θ, φ)Ym(θ, φ)ds = cnδnm

S Go Back where S is the unit sphere, however, spherical harmonics also have the Full Screen property that cn = 1 making them not only orthogonal, but orthonormal [1]. Also like associated Legendre polynomials, spherical harmonics are basis functions and any continuous function on the surface of a unit sphere can be Close

Quit Introduction to . . . The Heat Equation

������� Laplace’s Equation Harmonic Functions Spherical Harmonic . . . Mathematica Code

Home Page Figure 5: Spherical Harmonics

Title Page written as a linear combination of the spherical harmonics [2,1]. They can be thought of as the two-dimensional analog to the one-dimensional fourier JJ II series. Where the fourier series is used to estimate periodic vibrations in a string, spherical harmonics are used to estimate periodic functions defined J I on the two-dimensional surface of a sphere. Figure (5) shows a few spherical Page 32 of 45 harmonics plotted using surface normal displacement where green represents positive values and red represents negative values. The mathematica code Go Back used to generate this figure is available in appendix A.

Full Screen

Close

Quit 4.2.1. Spherical Function Expansion/Reconstruction The spherical harmonics can be used to reconstruct a spherical function f(φ, θ) the same way we did with the associated Legendre polynomials. We Introduction to . . . first calculate the coefficients using [1] The Heat Equation Laplace’s Equation 2π π Z Z Harmonic Functions m a`,m = f(θ, φ)Y` (θ, φ) sin θ dθ dφ. Spherical Harmonic . . . 0 0 Mathematica Code

Then we create a linear combination using the coefficients we calculated Home Page

N ` X X m Title Page f(θ, φ) ≈ a`,mY` (θ, φ) `=0 m=−` JJ II and once again, the higher we take N, the closer our approximation will be and if we let N = ∞, we can match any function exactly. One important J I thing to note is that the spherical harmonics are defined on imaginary num- bers, but generally when we are performing a spherical harmonic expansion Page 33 of 45 this way we are using only interested in approximating real-valued func- tions. Therefore, we use real spherical harmonics to do the expansion. Real Go Back spherical harmonics are just the real part of each function and are defined Full Screen

Close

Quit as √ 2Km cos (mφ)P m(cos θ) m > 0 √ ` ` m m −m Introduction to . . . Y` = 2K` sin (−mφ)P` (cos θ) m < 0  0 0 The Heat Equation K` P` cos(θ) Laplace’s Equation where s Harmonic Functions m 2` + 1 (` − |m|)! Spherical Harmonic . . . K` = · . 4π (` + |m|)! Mathematica Code Figure (6) shows a spherical function being reconstructed using real spheri- Home Page cal harmonics. The Mathematica code used to generate this figure is avail- able in appendix A. Title Page

5. Spherical Harmonic Lighting JJ II

Now that we have covered what spherical harmonics are and seen how pow- J I erful they can be for reconstructing complex spherical functions, we will take a brief look at how they are put to use in a real-world scenario: real-time Page 34 of 45 computer generated lighting. Go Back

5.1. Diffuse Surface Reflection Model Full Screen Also known as dot product lighting, the diffuse surface reflection model is Close a basic, but commonly used method for calculating diffuse light reflection

Quit Introduction to . . . The Heat Equation Laplace’s Equation Harmonic Functions Spherical Harmonic . . . Mathematica Code

Home Page

�������� Title Page

JJ II

J I

Page 35 of 45

Go Back

Figure 6: Spherical harmonic expansion of f(φ, θ) = sin (7θ) sin (3φ) + 2 Full Screen

Close

Quit on a computer generated surface. For each sample point on the surface and each light source, the light intensity is multiplied by the dot product of the surface normal vector and a vector in the direction of the light source [1]. Introduction to . . . When taking into account all of the light sources that affect the surface, The Heat Equation the total illumination on the surface is solved by integrating an illumination Laplace’s Equation function over a hemisphere of directions. The problem with this approach Harmonic Functions is that it is computationally expensive and too slow to be computed in real- time, so it is of no use for things that need to be rendered in real-time like Spherical Harmonic . . . video games. That is where spherical harmonics come in. Once the light Mathematica Code function is calculated, we can use spherical harmonics to approximate the Home Page illumination integral. In addition, a technique called stratified sampling can be employed which uses probability theory to sample points on the function Title Page and calculate the spherical harmonic values at these points. The spherical harmonic coefficients can then be pre-calculated numerically using a Monte JJ II Carlo estimator [1]

N J I 1 X cn = L(xj)yi(xj)w(xj) N Page 36 of 45 j=1

Go Back where xj are the pre-calculated sample points, L is the light intenisty, yi th is the i spherical harmonic, and w(xj) is a weighting function based on the probability of the point appearing in this location on the sphere. Run- Full Screen time integration has then been reduced to a series of simple multiply-add Close operations [1]. This process can result in very realistic scene lighting and

Quit Introduction to . . . The Heat Equation Laplace’s Equation Harmonic Functions Spherical Harmonic . . . Mathematica Code

Home Page

Title Page

JJ II

J I Figure 7: c Weta Digital

Page 37 of 45 has even been used in major motion pictures to reduce production time. Figure (7) and Figure (8) show spherical harmonic lighting being used in the Go Back movie Avatar from 20th Century Fox and the results are quite impressive. Full Screen

Close

Quit Introduction to . . . The Heat Equation Laplace’s Equation Harmonic Functions Spherical Harmonic . . . Mathematica Code

Home Page

Title Page

JJ II

J I

Page 38 of 45

Go Back Figure 8: c 2009 20th Century Fox

Full Screen

Close

Quit A. Mathematica Code

A.1. Figure (2): Heat Equation Solution Introduction to . . . Plot3D[Sum[2/n (-1)^(n + 1) Sin[n x] E^(-k n^2 t), {n, m}], {x, The Heat Equation 0, \[]}, {t, .01, 1.5}, Laplace’s Equation AxesLabel -> {Style["Position", 18], Style["Time", 18], Harmonic Functions Style["Temp", 18]}, Spherical Harmonic . . . PlotRange -> Full, Mathematica Code MaxRecursion -> 3,

PlotPoints -> 30, Home Page ColorFunctionScaling -> False,

ColorFunction -> Function[{x, y, z}, Hue[.0895/(z + .15)]], Title Page ImageSize -> Full ] JJ II

A.2. Figure (3): Legendre Polynomials J I lp = {}; Page 39 of 45 For[l = 0, l < 3, l++,

For[m = 0, m <= l, m++, Go Back If[Length[lp] <= 4, AppendTo[lp, LegendreP[l, m, x]] Full Screen ] ] Close

Quit ]

Plot[lp, {x, -1, 1}, AxesLabel -> {x, "f(x)"}, Introduction to . . . ImageSize -> Large, The Heat Equation PlotLegends -> "Expressions" Laplace’s Equation ] Harmonic Functions Spherical Harmonic . . . A.3. Figure (4): Legendre Expansion Mathematica Code f[x_] = (-1.2 x^6 + 3.1 x^5 - 2.1 x^4 + 6 x^3 - 3 x^2 + 2 x - 2); Home Page xx = 6; lplots = {}; Title Page For[i = 0, i <= xx, i = i + 2, tbl = Table[ JJ II (2 n + 1)/2 Integrate[f[x]*LegendreP[n, x], {x, -1, 1}], J I {n, 0, xx} ]; Page 40 of 45 g[x_] = Sum[tbl[[n + 1]]*LegendreP[n, 0, x], {n, 0, i}]; AppendTo[lplots, Go Back Plot[{g[x], f[x]}, {x, -2, 2}, Full Screen PlotLabel -> Style[Row@{"N = ", i}, 8], PlotStyle -> {{Thickness[0.004]}, {Thickness[0.004], Dashed}}, Close

Quit Ticks -> {{-1, 1}, None}, PlotRange -> {{-1, 1}, {-10, 5}} ] Introduction to . . . ]; ]; The Heat Equation gr = GraphicsGrid[{lplots[[1 ;; 2]], lplots[[3 ;; 4]]}, Laplace’s Equation ImageSize -> Full] Harmonic Functions Spherical Harmonic . . . A.4. Figure (5): Spherical Harmonics Mathematica Code

SphericalPlot3D[ Home Page Abs[Re[SphericalHarmonicY[l, m, t, p]]], {t, 0, 2 \[Pi]}, {p, -\[Pi], \[Pi]}, Title Page ColorFunction -> Function[ {x, y, z, t, p, r}, JJ II If[Re[SphericalHarmonicY[l, m, t, p]] >= 0, RGBColor[0.56, 0.69, 0.24], RGBColor[.82, .4, .36]] J I ], Page 41 of 45 ColorFunctionScaling -> False, PerformanceGoal -> "Quality", Go Back MaxRecursion -> ControlActive[0, 3],

PlotPoints -> {24, 12}, Full Screen Boxed -> False,

Axes -> False, Close

Quit SphericalRegion -> True, Mesh -> None ] Introduction to . . . The Heat Equation A.5. Figure (6): Spherical Harmonic Expansion Laplace’s Equation gx[\[Phi]_, \[Theta]_] = 2 + Sin[7 \[Theta]] Sin[3 \[Phi]]; Harmonic Functions Spherical Harmonic . . . K[l_, m_] := Mathematica Code Sqrt[(2 l + 1)/(4 \[Pi]) *Factorial[(l - Abs[m])]/ Factorial[(l + Abs[m])] Home Page ]; SH[l_, m_, \[Theta]_, \[Phi]_] := Title Page If[m > 0, Sqrt[2]*K[l, m]*Cos[m*\[Phi]]*LegendreP[l, m, Cos[\[Theta]]], JJ II If[m < 0, Sqrt[2]*K[l, m]*Sin[-m*\[Phi]]*LegendreP[l, -m, Cos[\[Theta]]], J I K[l, 0]*LegendreP[l, 0, Cos[\[Theta]]] ] Page 42 of 45 ]; Go Back sh = {}; Full Screen bands = {6, 9, 12, 16}; vals = {}; Close

Quit plots = {}; For[a = 1, a <= Length[bands], a++, For[l = 0, l < bands[[a]], l++, Introduction to . . . For[m = -l, m <= l, m++ , The Heat Equation AppendTo[sh, SH[l, m, \[Theta], \[Phi]]] ] Laplace’s Equation ]; Harmonic Functions c = Length[sh]; Spherical Harmonic . . . tbl = Table[ Mathematica Code Integrate[ gx[\[Phi], \[Theta]]*sh[[n]]*Sin[\[Theta]], {\[Phi], 0, Home Page 2 \[Pi]}, {\[Theta], 0, \[Pi]}], {n, 1, c, 1}]; Title Page AppendTo[vals, 0]; For[k = 1, k <= c, k++, vals[[a]] = vals[[a]] + sh[[k]]*tbl[[k]]]; AppendTo[ JJ II plots, J I SphericalPlot3D[

vals[[a]], {\[Phi], 0, 2 \[Pi]}, {\[Theta], 0, \[Pi]}, Page 43 of 45 PlotPoints -> 20, MaxRecursion -> 4, Go Back Mesh -> None, Boxed -> False, Full Screen Axes -> False, ColorFunction -> (ColorData["BlueGreenYellow"][#6] &), Close

Quit PlotLabel -> Style[Row@{"N = ", bands[[a]]}, 12] ]

]; Introduction to . . . ]; The Heat Equation actual = SphericalPlot3D[ Laplace’s Equation gx[\[Phi], \[Theta]], {\[Phi], 0, 2 \[Pi]}, {\[Theta], 0, \[Pi]}, Harmonic Functions PlotPoints -> 20, MaxRecursion -> 4, Spherical Harmonic . . . Mesh -> None, Mathematica Code Boxed -> False, Home Page Axes -> False,

ColorFunction -> (ColorData["BlueGreenYellow"][#6] &), Title Page PlotLabel -> Style[Row@{"f(\[Phi],\[Theta]) = ", JJ II Evaluate[gx[\[Phi], \[Theta]]]}, 12] ]; J I

GraphicsGrid[{{actual, plots[[1 ;; 2]]}, {plots[[3 ;; 4]]}}] Page 44 of 45

Go Back

Full Screen

Close

Quit References

[1] Robin Green. Spherical Harmonic Lighting: The Gritty Details Introduction to . . . http://www1.cs.columbia.edu/∼cs4162/slides/spherical-harmonic- lighting.pdf The Heat Equation Laplace’s Equation [2] Volker Schonefeld. 2005 Spherical Harmonics. Harmonic Functions https://www.math.ucdavis.edu/ tracy/courses/math22B/22BBook.pdf Spherical Harmonic . . . Mathematica Code [3] N.A. Electrostatic Fields II

https://faculty.washington.edu/seattle/physics227/reading/spherical- Home Page coords.pdf.

Title Page [4] Carl David. The Laplacian in Spherical Polar Coordinates http://digitalcommons.uconn.edu/cgi/viewcontent.cgi?article=1034 JJ II [5] N.A. 2013 Separation of Variables for Laplace’s Equation https://www.youtube.com/watch?v=eibQuD0taAI J I

[6] Paul Dawkins Solving the Heat Equation Page 45 of 45 http://tutorial.math.lamar.edu/Classes/DE/SeparationofVariables.aspx Go Back [7] Wikipedia Spherical Harmonics http://en.wikipedia.org/wiki/Spherical harmonics Full Screen

Close

Quit