Docsity

Course Lecture Notes - Computational Physics | PHYS 4007, Study notes of Physics

Partial preview of the text

Download Course Lecture Notes - Computational Physics | PHYS 4007 and more Study notes Physics in PDF only on Docsity!

PHYS-4007/5007: Computational Physics

Course Lecture Notes

Section V

Dr. Donald G. Luttermoser East Tennessee State University

Version 4.

Abstract

These class notes are designed for use of the instructor and students of the course PHYS-4007/5007: Computational Physics taught by Dr. Donald Luttermoser at East Tennessee State University.

V–2 PHYS-4007/5007: Computational Physics

compensate for these errors where type and extent of error is known.

v) In other cases, the uncertainties resulting from these errors must be estimated and combined with uncertainties from statistical fluctuations.

d) Approximation Errors: i) These arise from simplifying the mathematics so that the problem can be solved on a computer: → infinite series being replaced by a finite sum

ex^ =

∑∞ n=

xn n! (V-1) ≈ ∑N n=

xn n! = ex^ + E(x, N). (V-2)

ii) In Eq. (V-2), E(x, N) is the total absolute er- ror.

iii) This type of error also is called algorithmic error, the remainder, or truncation error.

iv) To have a small approximation error, N  x in Eq. (V-2).

e) Roundoff Errors: i) Inaccuracies in stated numbers on a computer due to a finite (typically small) number of bits being used on a computer to represent numbers.

ii) The total number of possible “machine” numbers

Donald G. Luttermoser, ETSU V–

is much less than the total number of “real” num- bers (which of course is infinite).

iii) The more calculations a computer does, the larger the roundoff error.

iv) This error can cause some algorithms to become unstable.

v) If the roundoff error value > value of the number being represented =⇒ the result is referred to as garbage.

vi) For instance, a computer may compute the fol- lowing as

2

) −

vii) We need to worry about significant figures on a computer:

  • On a 32-bit CPU, single precision is stored in one word → 4 bytes (REAL∗4 or REAL).
  • On a 32-bit CPU, double precision is stored in two words → 8 bytes (REAL∗8).
  • Trailing digits beyond these “bytes” are lost (if you ask a code to print more digits out, the printed digits should be considered as garbage ).

f) What kind of error do we make in representing a real number in a floating point number system?

Donald G. Luttermoser, ETSU V–

  1. Uncertainties. a) The term error signifies a deviation of the result from some “true” value. i) However, since we often cannot know the “true” value of a measurement prior to the experiment, we can only determine estimates of the errors inherent to the experiment.

ii) The difference between two measurements is called the discrepancy between the results.

iii) The discrepancy arises due to the fact that we can only determine the results to a certain uncer- tainty.

b) There are two classes of uncertainties: i) The most prominent type: Those which result from fluctuations in repeated measurements of data from which the results are calculated.

ii) The secondary type: Those which result from the fact that we may not always know the appropriate theoretical formula for expressing the result.

c) Probable Error: The magnitude of the error which we estimate we have made in our determination of the results. i) This does not mean that we expect our results to be wrong by this amount.

ii) Instead, it means that if we are wrong in our re- sults, it probably won’t be wrong by more than the probable error.

V–6 PHYS-4007/5007: Computational Physics

iii) As such, probable error will be synonymous with uncertainty in a measurement or calculation.

  1. Implications for Numerical Computing. a) Most numbers that we use in floating point computations must be presumed to be somewhat in error. They may be rounded from the values we have in mind by: i) Input conversion errors.

ii) Inexact arithmetic from the limited significance of the input numbers due to limited RAM sizes of the computer.

b) How is the value of function f (x) affected by errors in the argument x? i) Suppose x has a relative error of  so that we ac- tually use the value x(1 + ).

ii) Then the value of the function is f (x(1 + )).

iii) If f is differentiable, the absolute error in the value of f caused by the error in x can be approx- imated by f (x + x) − f (x) ≈ xf ′(x). (V-3)

iv) The relative error is then f (x + x) − f (x) f (x) ≈ x f ′(x) f (x)

. (V-4)

v) As we had above, suppose f (x) = ex, then the ab- solute error is approximately xex^ and the relative error is ex.

V–8 PHYS-4007/5007: Computational Physics

B. Useful Theorems in Computational Physics.

  1. Intermediate Value Theorem. Let f (x) ba a continuous func- tion on the closed interval [a, b]. If for some number α and for some x 1 , x 2 ∈ [a, b] we have f (x 1 ) ≤ α ≤ f (x 2 ), then there is some point c ∈ [a, b] such that α = f (c). (V-5) Here the notation [a, b] means the interval consisting of the real numbers x such that a ≤ x ≤ b.
  2. Rolle’s Theorem. Let f (x) be continuous on the closed, finite interval [a, b] and differentiable on (a, b). If f (a) = f (b) = 0, there is a point c ∈ (a, b) such that f ′(c) = 0. (V-6)

Here the notation (a, b) means the interval consisting of the real numbers x such that a < x < b.

  1. Mean-Value Theorem for Integrals. Let g(x) be a non- negative function integrable on the interval [a, b]. If f (x) is con- tinuous on [a, b], then there is a point c ∈ [a, b] such that ∫ (^) b a f^ (x)g(x)^ dx^ =^ f^ (c)

∫ (^) b a g(x)^ dx^ (V-7) (more to come in §VII of the notes).

  1. Mean-Value Theorem for Derivatives. Let f (x) be continu- ous on the finite, closed interval [a, b] and differentiable on (a, b). Then there is a point c ∈ (a, b) such that f (b) − f (a) b − a =^ f^

′(c) (V-8)

(more to come in §VII of the notes).

Donald G. Luttermoser, ETSU V–

  1. Taylor’s Theorem (with Remainder). Let f (x) have the continuous derivative of order n + 1 on some interval (a, b) con- taining the points x and x◦. Set

f (x) = f (x◦) + f ′(x◦) 1! (x − x◦) + f ′′(x◦) 2! (x − x◦)^2 +

  • · · · + f (n)(x◦) n! (x − x◦)n^ + Rn+1(x). (V-9)

Then there is a number c between x and x◦ such that

Rn+1(x) = f^

(n+1)(c) (n + 1)! (x − x◦)n+1. (V-10)

  1. Let f (x) be a continuous function on the finite, closed interval [a, b]. Then f (x) assumes its maximum and minimum values on [a, b]; i.e., there are points x 1 , x 2 ∈ [a, b] such that

f (x 1 ) ≤ f (x) ≤ f (x 2 ) (V-11)

for all x ∈ [a, b].

  1. Integration by Parts. Let f (x) and g(x) be real values func- tions with derivatives continuous on [a, b]. Then ∫ (^) b a f^

′(t)g(t) dt = f (t)g(t)|t=b t=a −

∫ (^) b a f^ (t)g

′(t) dt. (V-12)

  1. Fundamental Theorem of Integral Calculus. Let f (x) be continuous on the interval [a, b], and let

F (x) =

∫ (^) x a f^ (t)^ dt^ for all^ x^ ∈^ [a, b].^ (V-13) Then F (x) is differentiable on (a, b) and

F ′(x) = f (x). (V-14)

Donald G. Luttermoser, ETSU V–

ii) This shows that even for small relative errors in b and c, the uncertainty in ac will be large since it is multiplied by b/a (remember b ≈ c  a).

iii) This subtraction cancellation pokes its ugly head in the series for e−x.

  1. Multiplicative Errors. a) Error in computer multiplication arises in the following way:

a = b × c =⇒ ac = bc × cc , (V-21) =⇒ ac a

(1 + b)(1 + c) (1 + a) ≈ 1 + b + c. (V-22)

Since b and c can have opposite signs, the error in ac is sometimes larger and sometimes smaller than the individ- ual errors in bc and cc.

b) Often, we can estimate an average roundoff error for a series of multiplications by assuming that the computer’s representation of a number differs randomly from the ac- tual number.

c) In these cases, we can use the random walk technique: i) Let R be the average total distance covered in N steps each of length r, then

R ≈

N r. (V-23)

ii) Each step of a multiplication has a roundoff error of length m, the machine’s precision.

V–12 PHYS-4007/5007: Computational Physics

iii) In the random walk analogy, the average relative error ro arising after a large number N of multi- plicative steps is then

ro '

N m. (V-24)

We will be making use of Eq. (V-24) many times in this course.

d) When roundoff errors do not occur randomly, careful anal- ysis is needed to predict the dependence of the error on the number of steps N. i) If there are no cancellations of error, the relative error may increase like N m.

ii) Some recursive algorithms where the production of errors is coherent (e.g., upward recursive Bessel functions), the error increases like N! m.

e) This is something to keep in mind when you hear about computer calculations requiring hours to complete. i) A fast computer may complete 10^10 floating-point operations per second. Hence, a program running for 3 CPU hours performs about 10^14 operations.

ii) Then, after 3 hours, we can expect roundoff errors to have accumulated to a relative importance of 107 m.

iii) For the error to be smaller than the answer, this demands that m < 10 −^7.

V–14 PHYS-4007/5007: Computational Physics

greatest value:

P (μmax) ≥ P (x 6 = μmax). (V-27)

d) The deviation di of any measurement xi from the mean μ of the parent distribution is defined as

di = xi − μ. (V-28)

i) Deviations are generally defined with respect to the mean for computational purposes.

ii) If μ is the true value of the quantity, then di is the true error in xi.

iii) The average deviation d for an infinite number of observations must vanish by virtue of the definition of the mean (see Eq. V-25):

Nlim →∞ d^ =^ Nlim →∞

  1 N

∑^ N i=

(xi − μ)

 

= (^) Nlim →∞

  1 N

∑^ N n=

xi

  (^) − μ = μ − μ = 0.

iv) The average deviation α, therefore, is defined as the average of the magnitudes of the deviations, which are given by the absolute values of the devi- ations:

α ≡ (^) Nlim →∞

  1 N

∑^ N n=

|xi − μ|

  (^). (V-29)

v) The average deviation is a measure of the disper- sion of the expected observations about the mean.

Donald G. Luttermoser, ETSU V–

e) The variance σ^2 is defined as the limit of the average of the squares of the deviations of the mean:

σ^2 ≡ (^) Nlim →∞

  1 N

∑^ N n=

(xi − μ)^2

  (^) = lim N →∞

  1 N

∑^ N n=

x^2 i

  (^) − μ^2. (V-30) i) The standard deviation σ is the square root of the variance.

ii) The standard deviation is thus the root mean square of the deviations, where we define the root mean square to be the square root of the mean or average of the square of an argument.

iii) In computational work, the standard deviation σ is considered an appropriate measure of the uncer- tainty of a measurement or a calculation.

  1. Errors in Algorithms. An algorithm is often characterized by its step size h or by the number of steps N it takes to reach its goal. If the algorithm is “good,” it should give an exact answer in the limit h → 0 or N → ∞. Here, we present methods for determining the error in your code. a) Let’s assume that an algorithm takes a large number of N steps to get a good answer and that the approximation error approaches zero like

apprx ' α Nβ^

. (V-31)

b) In Eq. (V-31), α and β are empirical constants that would change for different algorithms, and may be “constant” only for N → ∞.

Donald G. Luttermoser, ETSU V–

N−^1 /^2 m = 4 N−^3 , N^5 /^2 =

m

. (V-36)

b) For single precision on a 32-bit chip processor, m ' 10 −^7 , so the minimum total error is reached when

N^5 /^2 ' 4 10 −^7 N ' 1099

and

tot ' 1 N^2

N m = (8 × 10 −^7 ) + (33 × 10 −^7 ) ' 4 × 10 −^6.

c) This shows for a typical algorithm, most of the error is due to roundoff. Also, even though that this is the minimum error, the best we can do is to get some 40 times machine precision (in single precision).

d) As such, to reduce roundoff error, we should come up with a code that requires less steps (N) to achive convergence.

  1. Sections 3.12 and 3.13 of your textbook go into further details on optimizing error behavior and setting up an empirical error analysis. You should look these sections over in detail.

D. Propagation of Uncertainties.

  1. We will demonstrate the propagation of errors with a simple ex- ample. Suppose we wish to find the volume V of a box of length L, width W , and height H. a) We measure L◦, W◦, and H◦ and determine

V◦ = L◦ W◦ H◦. (V-37)

V–18 PHYS-4007/5007: Computational Physics

b) How do the uncertainties in L◦, W◦, and H◦ affect the uncertainty in V◦? Let L, W , H, and V be the actual (i.e., ‘true’) value, then ∆L = L◦ − L, ∆W = W◦ − W , and ∆H = H◦ − H.

c) The error in V is approximately the sum of the products of the errors in each dimension times the effect that di- mension has on the final value of V : ∆V ' ∆L

(∂V

∂L

)

  • ∆W

( ∂V

∂W

)

  • ∆H

( ∂V

∂H

) , (V-38)

of for our example, ∆V ' W◦ H◦ ∆L + L◦ H◦ ∆W + L◦ W◦ ∆H. (V-39) Dividing this equation by Eq. (V-37) gives ∆V V◦

∆L

L◦

∆W

W◦

∆H

H◦

. (V-40)

  1. In general, we do not know the actual errors in the determina- tion of any of the parameters. The following describes how we estimate the uncertainties. a) Let’s define x = f (u, v,.. .). (V-41)

b) Assume the most probable value for x is given by x = f (u, v,.. .). (V-42)

c) Individual results for x (xi) are found by individual mea- surements of other parameters, that is ui, vi,.. ., giving xi = f (ui, vi,.. .). (V-43)

d) Using Eq. (V-30), the variance in x is then

σ x^2 = (^) Nlim →∞

N

∑ (xi − x)^2. (V-44)