Physics 2 Lecture 4 Integration Lecture 4 Physics 2 Laboratory Monday, February 21st, 211 Integration is the flip-side of differentiation in fact, it is often possible to write a differential equation as an integral equation. Both formulations are useful analytically, and both are useful numerically as well. We ll start by defining some common physical problems that involve the ability to integrate, and then discuss the manner in which such integrals may be approximated numerically. 4.1 Physical Motivation There are two main areas of interest for us when it comes to integrating the first is a direct integral of a physical quantity, as an example: Given µ(x), the mass per unit length along some line, say, what is the total mass between x 1 and x 2? The answer is provided by noting that the infinitesimal mass enclosed in an interval of width dx, centered at x, is dm = µ(x) dx, and then the integral follows naturally: m = x2 x 1 µ(x) dx. (4.1) The second area of interest comes from an integral formulation of a differential equation. The simplest case of an ODE that can be turned into an integral equation is Newton s second law for time-varying force: dp dt = F (t), (4.2) an object moves under the influence of a force F (t), and we want to find its momentum. The solution, if you can call it that, is an integral equation, 1 of 14
4.1. PHYSICAL MOTIVATION Lecture 4 obtained by integrating both sides of the above with respect to time: p(t) p() = t F ( t) d t (4.3) where we assume the motion begins at t = (else replace the limits of integration on the right, and the initial momentum on the left). These two types of problem are, of course, related, I could easily pose the mass along the line problem as the solution for m(x) given the ODE dm dx = µ(x), but I make the distinction to focus on problems where the integral itself is of interest (like mass), versus problems where the integral is a useful form of solution (as is the case for, for example, electrostatic potentials). 4.1.1 Direct Integral Problems We have already encountered a role for integrals (aside from computing the amount of mass or charge in a specific region of space) the quantum mechanical wave-function, ψ(x) must be normalized we require that: ψ(x) ψ(x) dx = 1, (4.4) and this condition is imposed as a constraint, separate from the differential equation governing ψ(x) (Schrödinger s equation). If we have a solution, like the one we worked out last time for the infinite square well, of the form: ( n π x ) ψ(x) = A sin, (4.5) a then we must set A by requiring that: a A 2 sin 2( n π x ) dx = 1. (4.6) a In this case, we can do the integral immediately, and we see that the above equation is: A 2 1 2 a = 1 A = 2 a, (4.7) but suppose we had a numerical approximation to ψ(x), defined on a grid: ψ j = ψ(x j ) with x j = j x we would need an approximation to the integral in order to set the overall constant for ψ j. 2 of 14
4.1. PHYSICAL MOTIVATION Lecture 4 We know that ψ(x) ψ(x) dx represents the probability of finding a particle near x, but what about other quantities of interest? Suppose, for example, we had a particular quantity f(x), a function of position, and we wanted to know the average value for this quantity given the particle s position probability. The average value for f(x) would be f = ψ(x) f(x) ψ(x) dx, (4.8) where the sandwhiching occurs for reasons you ll see later on. The point is, we could calculate a particle s average position if we knew the probability of finding it in the vicinity of x, that would be: x = ψ(x) x ψ(x) dx. (4.9) For our infinite square well example, the average value of position for a particle in a box is: x = a 2 a sin2( n π x ) x dx = 1 a 2 a (4.1) But (4.8) is an example of a more general statistical quantity. Given a probability density ρ(x), associated with the probability of getting outcome x, the average value of any function of x, call it f(x), is: f = ρ(x) f(x) dx, (4.11) and in quantum mechanics, we understand ρ(x) = ψ(x) ψ(x) is a special form. In statistics, the averages of various polynomials in x are called the moments of the distribution ρ(x), so there s the first moment, that s x, the second moment, x 2, and so on. Each moment is itself an integral and requires that we start with a probability density that has ρ(x) dx = 1, and that we are able to compute the appropriate integrals to get the averages. Again, these integrals may be difficult to carry out by hand (not much of an excuse for using a computer), or impossible (a better motivation), or the densities themselves may be numerical approximations. 3 of 14
4.1. PHYSICAL MOTIVATION Lecture 4 Classical Probability Density Last week, we studied the quantum mechanical particle in a box a particle of mass m confined to an interval x [, a]. In quantum mechanics, the answer to many experimental questions can be determined using the wavefunction and calculating moments (via the probability density interpretation of ψ ψ). But we can view classical problems in terms of probability densities as well. For example, if we think of a particle of mass m that bounces back and forth between two walls (one at zero, one at a), we can associate a probability density with the particle s position. Since the mass travels with constant speed, and turns around instantaneously at the walls, the probability of finding it within dx of any point x in the box is a constant, ρ(x) = A. We require that this density be normalized, so that ρ(x) dx = a A dx = 1 (4.12) and then A = 1/a. Now we can compute the average position of the particle, x = x ρ(x) dx = a and higher moments can also be computed. x 1 dx = a/2, (4.13) a 4.1.2 Integrals as Solutions to Problems Integrals show up as the end-point to many problems, and as a natural formulation of solutions to differential equations. In many areas of physics there is a notion of superposition, the idea that if you know the solution to a partial differential equation with a point source, you can find the solution for an arbitrary source by adding up the point-solutions of the source. As an example, take an infinite line of charge, carrying charge-per-unitlength λ(x) = Q a e x2 /a 2 for constants Q and a. We want to know the electrostatic potential a height z above the midpoint of the line (so at x = ), 4 of 14
4.1. PHYSICAL MOTIVATION Lecture 4 the setup is shown in Figure 4.1. V =? r = x 2 + z 2 z dq = λ(x) dx dx x Figure 4.1: An infinite line of charge carries a known distribution λ(x) (charge per unit length) what is the electrostatic potential a height z above the point x = on the line? We know that each point along the line contributes to the potential as a point source that is, if a little box of width dx centered at x contains charge dq, then its contribution to the potential at the point of interest is: dv = dq 4 π ɛ x 2 + z 2. (4.14) We also know that the potential satisfies superposition, so that all we have to do is add up all of the contributions, they don t interact with one another. We can perform that addition by noting that dq = λ(x) dx, from the definition of λ(x), so that: λ(x) dx dv = 4 π ɛ x 2 + z V = λ(x) dx 2 4 π ɛ x 2 + z, (4.15) 2 and there it is, an integral that we have to compute. We can clean up the actual integral a bit by removing uninteresting constants, and noting that the integrand is even, V (z) = 2 Q 4 π ɛ z a e x2 /a 2 dx. (4.16) 1 + x 2 /z2 5 of 14
4.1. PHYSICAL MOTIVATION Lecture 4 To make the units clear, we ll nondimensionalize the integrand the constant a sets the scale for the Gaussian decay, so let x a q, then: V (z) = 2 Q 4 π ɛ z e q2 dq (4.17) 1 + a 2 q 2 /z2 the constants out front are just right for a potential, and the integral is ready for numerical approximation. In this particular case, the answer is a known function of z, we end up with: [ V (z) = Q 4 π ɛ a ] e y2 K (y 2 ) y z 2 a (4.18) where K is a modified Bessel function. Regardless of its name, in the general case, what we want is a numerical function that approximates the integral and returns that approximation for a given value of z. Another place where integrals show up as natural solutions is pendulum motion. For a pendulum, a bob of mass m is suspended by a string of length L, as in Figure 4.2. ŷ ˆx θ F T m mgŷ Figure 4.2: A mass m is attached to a string of length L it moves up and back. We know the forces in the x and y direction, so Newton s second law reads: m ẍ = F T sin θ m ÿ = F T cos θ m g. (4.19) In addition, we know that the pendulum bob is constrained to travel along a path given by: x(t) = L sin θ(t) y(t) = L cos θ(t). (4.2) 6 of 14
4.1. PHYSICAL MOTIVATION Lecture 4 Taking the second derivatives of x(t) and y(t) and inputting them into (4.19), we get the angular acceleration associated with θ(t): θ = g L sin θ. (4.21) If we( multiply this equation by θ, then the left-hand side can be written as d 1 θ ) dt 2 2, and the right-hand side is g d L dt cos θ, both total derivatives in time, then: θ 2 = 2 g cos θ + A (4.22) L and to get a nice form, we let A 2 g L cos θ M, then [ ] 2 g 1/2 θ = ± L (cos θ cos θ M). (4.23) Now, we know that θ = when we get to the turning points of the motion, giving us a nice physical interpretation for θ M it is the maximum angle that the bob can make during its swing. Suppose we want the period of oscillation, a quantity that should be obtainable by integrating (4.23). In order to avoid the choice of sign for θ, let s take a well-defined quarter of the period as the bob swings from θ M to, the minus sign is relevant, and our quarter period is: L 2 g The period is T = 4 t, so: L T = 4 2 g θ M θm dθ cos θ cos θm = t. (4.24) [cos θ cos θ M ] 1/2 dθ. (4.25) The integral here can be turned into a familiar form, from a certain point of view. Note that 1 2 (1 cos θ) = sin2 (θ/2), then we have: cos θ cos θ M = ( 1 2 sin 2 (θ/2) ) ( 1 2 sin 2 (θ M /2) ) = 2 ( sin 2 (θ M /2) sin 2 (θ/2) ). (4.26) Take a substitution of the form sin(θ/2) = A sin(φ), motivated by the above, and since sin(θ M /2) = A sin(φ M ) is just a constant, we set A sin(θ M /2) 7 of 14
4.2. METHODS OF NUMERICAL INTEGRATION Lecture 4 so that φ M = 1 2 π, for simplicity. Now the difference of cosines in (4.26) can be written: cos θ cos θ M = 2 A 2 ( 1 sin 2 φ ) = 2 A 2 cos 2 φ. (4.27) To finish the change of variables, note that: 1 2 cos(θ/2) dθ = A cos(φ) dφ (4.28) so that the period integral in (4.25) is 1 L 2 π 2 A cos(φ) dφ T = 4 2 g cos(θ/2) 2 A cos φ (4.29) and use the trigonometric identity: cos 2 (θ/2) + sin 2 (θ/2) = 1 to replace the cos(θ/2) on the right with 1 A 2 sin 2 φ. Our final form is 1 L 2 π dφ T = 4 A sin(θ M /2). (4.3) g 1 A 2 sin 2 φ The integral here has a name, it is called an elliptic integral, and numerical values exist in tables. But those tables had to be made somehow... 4.2 Methods of Numerical Integration As with our discussion of numerical ODE solving, the starting point for numerical integration proceeds from a truncation of the formal definition of an integral. For a function f(x), defined on a uniformly spaced grid: f j f(x j ), for x j = j x (starting at j =, say), we know that the integral (when it exists) of f(x) from to x f is defined as: xf f(x) dx = lim x j= N f j x x N+1 = (N + 1) x = x f. (4.31) The first method we will consider just eliminates the limit, and replaces equality with, so that our approximation reads: xf f(x) dx N f j x. (4.32) j= 8 of 14
4.2. METHODS OF NUMERICAL INTEGRATION Lecture 4 This approach can be understood pictorially as an approximation to the area under a curve f(x) in one dimension. In Figure 4.3, we see the box area for the interval x j to x j+1 our integral approximation comes from adding up these box areas. As x goes to zero, the horizontal segment at the top of the box better approximates f(x j ) over the interval, so the box area approximation becomes closer to the integral value. f(x) f j box area = f j x x j x j+1 x Figure 4.3: Approximating the area under the curve using simple boxes. We can refine the area by cutting out the triangular segment associated with the box, as shown in Figure 4.4. Here, the approximation reads: xf f(x) dx = 1 2 = N j= 1 2 (f j + f j+1 ) x = 1 2 N f j x 1 2 f x + 1 2 j= N f j x + 1 2 j= N+1 k=1 f k x N f j x + 1 2 f N+1 x j= N f j x 1 2 f(x ) x + 1 2 f(x N) x. j= (4.33) where in the first line, we have rewritten the second sum using k j + 1, then re-labelled k as j in the second line. This interesting rewrite relates the two methods, which apparently only differ by the subtraction of half the 9 of 14
4.2. METHODS OF NUMERICAL INTEGRATION Lecture 4 f(x) f j f j+1 area = f j x 1 2 x (f j f j+1 ) x j x j+1 x Figure 4.4: Approximating the area under the curve with a refined box, the triangular portion at the top is cut out (using the area of a triangle, one half base times height). endpoint values. The method here, with the endpoint correction, is known as the trapezoidal rule. 1 of 14
4.2. METHODS OF NUMERICAL INTEGRATION Lecture 4 Lab In this lab, you will implement both the box integral, and trapezoidal methods. The first problem will ensure that these are working correctly, and then subsequent problems will address physical applications. Use g = 9.8 m/s 2. Problem 4.1 Write two integrators, Bint and Tint, implementing both of the methods discussed in the notes. Your integrators should take, as input, a function f, the lower and upper integration limits, x and xf, the number of points in your grid, Nsize, and output approximations to the integral I = x f x f(x) dx. Test your pair on the function: f(x) = 1 2 x2 (4.34) for x= 1 to xf= 3 using Nsize= 1. Write the result of the exact integral, and both approximations (five digits) below: 11 of 14
4.2. METHODS OF NUMERICAL INTEGRATION Lecture 4 Problem 4.2 Using your more accurate integrator, compute an approximation to the integral I = 1 sin(x) x dx (4.35) and write your answer (accurate to at least five digits with respect to the true answer) below include the number of steps you needed to get this accuracy, and describe how you determined the accuracy without knowing the exact value: 12 of 14
4.2. METHODS OF NUMERICAL INTEGRATION Lecture 4 Problem 4.3 Using the Gaussian density: ρ(x) = A e x2, find A, and the first two moments of the distribution for x= 1, xf= 1 and write them below Note that the Gaussian integral: e x2 dx = π, is a well-known result, which you are recovering here numerically. Problem 4.4 Q 4 π ɛ a Apply your integrator to (4.17) with a = 2 m, value for numerical infinity, and justify your choice: = 1 V first choose a Write the numerical value of the potential at z = 2 a below, and check your result using the built-in function BesselK. Sketch the curve of V (z) for z = 1 1 m. 13 of 14
4.2. METHODS OF NUMERICAL INTEGRATION Lecture 4 Problem 4.5 A pendulum of length L = 1 m that hangs 1 m above the ground starts a height.5 m above the ground what is the period of oscillation for this pendulum? What would the linearized period be (i.e. the one you use in introductory physics, assuming simple harmonic motion)? 14 of 14