Docsity

Computação cientifica II - nm3red, Notas de estudo de Engenharia Elétrica

Toggle sidebar
bg1
Chapter 1
Mathematical Preliminaries
and Error Analysis
1.1 Introduction
This book examines problems that can be solved by methods of approximation,
techniques we call numerical methods. We begin by considering some of the math-
ematical and computational topics that arise when approximating a solution to a
problem.
Nearly all the problems whose solutions can be approximated involve continuous
functions, so calculus is the principal tool to use for deriving numerical methods
and verifying that they solve the problems. The calculus definitions and results
included in the next section provide a handy reference when these concepts are
needed later in the book.
There are two things to consider when applying a numerical technique to solve
a problem. The first and most obvious is to obtain the approximation. The equally
important second objective is to determine a safety factor for the approximation:
some assurance, or at least a sense, of the accuracy of the approximation. Sections
1.3 and 1.4 deal with a standard difficulty that occurs when applying techniques
to approximate the solution to a problem: Where and why is computational error
produced and how can it be controlled?
The final section in this chapter describes various types and sources of mathe-
matical software for implementing numerical methods.
1.2 Review of Calculus
The limit of a function at a specific number tells, in essence, what the function
values approach as the numbers in the domain approach the specific number. This
is a difficult concept to state precisely. The limit concept is basic to calculus, and the
major developments of calculus were discovered in the latter part of the seventeenth
century, primarily by Isaac Newton and Gottfried Leibnitz. However, it was not
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Pré-visualização parcial do texto

Baixe Computação cientifica II - nm3red e outras Notas de estudo em PDF para Engenharia Elétrica, somente na Docsity!

Chapter 1

Mathematical Preliminaries

and Error Analysis

1.1 Introduction

This book examines problems that can be solved by methods of approximation, techniques we call numerical methods. We begin by considering some of the math- ematical and computational topics that arise when approximating a solution to a problem. Nearly all the problems whose solutions can be approximated involve continuous functions, so calculus is the principal tool to use for deriving numerical methods and verifying that they solve the problems. The calculus definitions and results included in the next section provide a handy reference when these concepts are needed later in the book. There are two things to consider when applying a numerical technique to solve a problem. The first and most obvious is to obtain the approximation. The equally important second objective is to determine a safety factor for the approximation: some assurance, or at least a sense, of the accuracy of the approximation. Sections 1.3 and 1.4 deal with a standard difficulty that occurs when applying techniques to approximate the solution to a problem: Where and why is computational error produced and how can it be controlled? The final section in this chapter describes various types and sources of mathe- matical software for implementing numerical methods.

1.2 Review of Calculus

The limit of a function at a specific number tells, in essence, what the function values approach as the numbers in the domain approach the specific number. This is a difficult concept to state precisely. The limit concept is basic to calculus, and the major developments of calculus were discovered in the latter part of the seventeenth century, primarily by Isaac Newton and Gottfried Leibnitz. However, it was not

2 CHAPTER 1. MATHEMATICAL PRELIMINARIES AND ERROR ANALYSIS

until 200 years later that Augustus Cauchy, based on work of Karl Weierstrass, first expressed the limit concept in the form we now use. We say that a function f defined on a set X of real numbers has the limit L at x 0 , written limx→x 0 f (x) = L, if, given any real number ε > 0, there exists a real number δ > 0 such that |f (x) − L| < ε whenever 0 < |x − x 0 | < δ. This definition ensures that values of the function will be close to L whenever x is sufficiently close to x 0. (See Figure 1.1.)

Figure 1.

x

f ( x )

L 1 e

L 2 e

L

x 0 2 d x 0 x 0 1 d

f

A function is said to be continuous at a number in its domain when the limit at the number agrees with the value of the function at the number. So, a function f is continuous at x 0 if limx→x 0 f (x) = f (x 0 ), and f is continuous on the set X if it is continuous at each number in X. We use C(X) to denote the set of all functions that are continuous on X. When X is an interval of the real line, the parentheses in this notation are omitted. For example, the set of all functions that are continuous on the closed interval [a, b] is denoted C[a, b]. The limit of a sequence of real or complex numbers is defined in a similar manner. An infinite sequence {xn}∞ n=1 converges to a number x if, given any ε > 0, there exists a positive integer N (ε) such that |xn − x| < ε whenever n > N (ε). The notation limn→∞ xn = x, or xn → x as n → ∞, means that the sequence {xn}∞ n= converges to x.

[Continuity and Sequence Convergence] If f is a function defined on a set X of real numbers and x 0 ∈ X, then the following are equivalent:

a. f is continuous at x 0 ;

b. If {xn}∞ n=1 is any sequence in X converging to x 0 , then

lim n→∞ f (xn) = f (x 0 ).

4 CHAPTER 1. MATHEMATICAL PRELIMINARIES AND ERROR ANALYSIS

functions are in C∞(X), where X consists of all numbers at which the function is defined. The next results are of fundamental importance in deriving methods for error estimation. The proofs of most of these can be found in any standard calculus text.

[Mean Value Theorem] If f ∈ C[a, b] and f is differentiable on (a, b), then a number c in (a, b) exists such that (see Figure 1.3)

f ′(c) = f (b) − f (a) b − a

Figure 1.

y

a c b x

Slope f 9 ( c )

Parallel lines

Slope b 2 a

f ( b ) 2 f ( a )

y 5 f ( x )

The following result is frequently used to determine bounds for error formulas.

[Extreme Value Theorem] If f ∈ C[a, b], then c 1 and c 2 in [a, b] exist with f (c 1 ) ≤ f (x) ≤ f (c 2 ) for all x in [a, b]. If, in addition, f is differentiable on (a, b), then the numbers c 1 and c 2 occur either at endpoints of [a, b] or where f ′^ is zero.

As mentioned in the preface, we will use the computer algebra system Maple whenever appropriate. We have found this package to be particularly useful for symbolic differentiation and plotting graphs. Both techniques are illustrated in Ex- ample 1.

1.2. REVIEW OF CALCULUS 5

EXAMPLE 1 Use Maple to find maxa≤x≤b |f (x)| for

f (x) = 5 cos 2x − 2 x sin 2x,

on the intervals [1, 2] and [0. 5 , 1]. We will first illustrate the graphing capabilities of Maple. To access the graphing package, enter the command

with(plots);

A list of the commands within the package are then displayed. We define f by entering

f:= 5cos(2x)-2xsin(2*x);

The response from Maple is

f := 5 cos(2x) − 2 x sin(2x)

To graph f on the interval [0. 5 , 2], use the command

plot(f,x=0.5..2);

We can determine the coordinates of a point of the graph by moving the mouse cursor to the point and clicking the left mouse button. The coordinates of the point to which the cursor is pointing appear in the white box at the upper left corner of the Maple screen, as shown in Figure 1.4. This technique is useful for estimating the axis intercepts and extrema of functions.

Figure 1.

1.2. REVIEW OF CALCULUS 7

an endpoint. Since f (1) = − 3 .899329037 and f (2) = − 0 .241008124, the maximum magnitude occurs at the critical point and

max 1 ≤x≤ 2 |f (x)| = max 1 ≤x≤ 2 |5 cos 2x − 2 x sin 2x| ≈ |f (1.358229874)| = 5. 675301338.

If we try to solve g(x) = 0 for 0. 5 ≤ x ≤ 1, we find that when we enter

fsolve(g,x,0.5..1);

Maple responds with

fsolve(−12 sin(2x) − 4 x cos(2x), x,. 5 ..1)

This indicates that Maple could not find a solution in [0. 5 , 1], for the very good reason that there is no solution in this interval. As a consequence, the maximum occurs at an endpoint on the interval [0. 5 , 1]. Since f (0.5) = 1.860040545 and f (1) = − 3 .899329037, we have

max

  1. 5 ≤x≤ 1 |f (x)| = max
  2. 5 ≤x≤ 1 |5 cos 2x − 2 x sin 2x| = |f (1)| = 3. 899329037.

The integral is the other basic concept of calculus that is used extensively. The Riemann integral of the function f on the interval [a, b] is the following limit, provided it exists.

∫ (^) b

a

f (x) dx = lim max ∆xi→ 0

∑^ n

i=

f (zi) ∆xi,

where the numbers x 0 , x 1 ,... , xn satisfy a = x 0 < x 1 < · · · < xn = b and where ∆xi = xi − xi− 1 , for each i = 1, 2 ,... , n, and zi is arbitrarily chosen in the interval [xi− 1 , xi]. A function f that is continuous on an interval [a, b] is also Riemann integrable on [a, b]. This permits us to choose, for computational convenience, the points xi to be equally spaced in [a, b] and for each i = 1, 2 ,... , n, to choose zi = xi. In this case ∫ (^) b

a

f (x) dx = lim n→∞

b − a n

∑^ n

i=

f (xi),

where the numbers shown in Figure 1.5 as xi are xi = a + (i(b − a)/n).

Figure 1.

8 CHAPTER 1. MATHEMATICAL PRELIMINARIES AND ERROR ANALYSIS

y

x

y 5 f ( x )

a 5 x 0 x 1 x 2... x (^) i 21 x (^) i... x (^) n 21 b 5 x (^) n

Two more basic results are needed in our study of numerical methods. The first is a generalization of the usual Mean Value Theorem for Integrals.

[Mean Value Theorem for Integrals] If f ∈ C[a, b], g is integrable on [a, b] and g(x) does not change sign on [a, b], then there exists a number c in (a, b) with ∫ (^) b

a

f (x)g(x) dx = f (c)

∫ (^) b

a

g(x) dx.

When g(x) ≡ 1, this result reduces to the usual Mean Value Theorem for Inte- grals. It gives the average value of the function f over the interval [a, b] as

f (c) =

b − a

∫ (^) b

a

f (x) dx.

(See Figure 1.6.) Figure 1.

x

y

f ( c )

y f ( x )

a c b

The next theorem presented is the Intermediate Value Theorem. Although its statement is not difficult, the proof is beyond the scope of the usual calculus course.

10 CHAPTER 1. MATHEMATICAL PRELIMINARIES AND ERROR ANALYSIS

[Taylor’s Theorem] Suppose f ∈ Cn[a, b] and f (n+1)^ exists on [a, b]. Let x 0 be a number in [a, b]. For every x in [a, b], there exists a number ξ(x) between x 0 and x with f (x) = Pn(x) + Rn(x), where

Pn(x) = f (x 0 ) + f ′(x 0 )(x − x 0 ) + f ′′(x 0 ) 2!

(x − x 0 )^2 + · · · + f (n)(x 0 ) n!

(x − x 0 )n

∑^ n

k=

f (k)(x 0 ) k!

(x − x 0 )k

and Rn(x) =

f (n+1)(ξ(x)) (n + 1)!

(x − x 0 )n+1.

Here Pn(x) is called the nth Taylor polynomial for f about x 0 , and Rn(x) is called the truncation error (or remainder term) associated with Pn(x). Since the number ξ(x) in the truncation error Rn(x) depends on the value of x at which the polynomial Pn(x) is being evaluated, it is actually a function of the variable x. However, we should not expect to be able to explicitly determine the function ξ(x). Taylor’s Theorem simply ensures that such a function exists, and that its value lies between x and x 0. In fact, one of the common problems in numerical methods is to try to determine a realistic bound for the value of f (n+1)(ξ(x)) for values of x within some specified interval. The infinite series obtained by taking the limit of Pn(x) as n → ∞ is called the Taylor series for f about x 0. In the case x 0 = 0, the Taylor polynomial is often called a Maclaurin polynomial, and the Taylor series is called a Maclaurin series. The term truncation error in the Taylor polynomial refers to the error involved in using a truncated (that is, finite) summation to approximate the sum of an infinite series.

EXAMPLE 3 Determine (a) the second and (b) the third Taylor polynomials for f (x) = cos x about x 0 = 0, and use these polynomials to approximate cos(0.01). (c) Use the third Taylor polynomial and its remainder term to approximate

0 cos^ x dx. Since f ∈ C∞(IR), Taylor’s Theorem can be applied for any n ≥ 0. Also,

f ′(x) = − sin x, f ′′(x) = − cos x, f ′′′(x) = sin x, and f (4)(x) = cos x,

so f (0) = 1, f ′(0) = 0, f ′′(0) = − 1 , and f ′′′(0) = 0.

1.2. REVIEW OF CALCULUS 11

a.For n = 2 and x 0 = 0, we have

cos x = f (0) + f ′(0)x +

f ′′(0) 2!

x^2 +

f ′′′(ξ(x)) 3!

x^3

= 1 −

x^2 +

x^3 sin ξ(x),

where ξ(x) is some (unknown) number between 0 and x. (See Figure 1.8.)

Figure 1. y

x

y 5 cos x

y 5 P 2 ( x ) 5 1 2 q x^2

1

2 q q

2 p p

When x = 0.01, this becomes

cos 0.01 = 1 −

(0.01)^2 +

(0.01)^3 sin ξ(0.01) = 0.99995 +

10 −^6

sin ξ(0.01).

The approximation to cos 0.01 given by the Taylor polynomial is therefore 0 .99995. The truncation error, or remainder term, associated with this ap- proximation is

10 −^6 6

sin ξ(0.01) = 0. 16 × 10 −^6 sin ξ(0.01),

where the bar over the 6 in 0.16 is used to indicate that this digit repeats indefinitely. Although we have no way of determining sin ξ(0.01), we know that all values of the sine lie in the interval [− 1 , 1], so the error occurring if we use the approximation 0.99995 for the value of cos 0.01 is bounded by

| cos(0.01) − 0. 99995 | = 0. 16 × 10 −^6 sin ξ(0.01) ≤ 0. 16 × 10 −^6.

Hence the approximation 0.99995 matches at least the first five digits of cos 0.01. Using standard tables we find that cos 0.01 = 0.99995000042, so the approximation actually gives agreement through the first nine digits. The error bound is much larger than the actual error. This is due in part to the poor bound we used for |sin ξ(x)|.

1.2. REVIEW OF CALCULUS 13

The true value of sin 0.1 to nine decimal places is 0.099833417, so the approx- imation derived from the Taylor polynomial is in error by

| 0. 099833417 − 0. 09983 | ≈ 8. 4 × 10 −^8 ,

which is essentially the same as the error bound derived from the Taylor poly- nomial.

We can use a computer algebra system to simplify the calculations in Example

  1. In the system Maple, we define f by

f:=cos(x);

Maple allows us to place multiple statements on a line, and to use a colon to suppress Maple responses. For example, we obtain the third Taylor polynomial with

s3:=taylor(f,x=0,4): p3:=convert(s3, polynom);

The statement s3:=taylor(f,x=0,4) determines the Taylor polynomial about x 0 = 0 with four terms (degree 3) and its remainder. The statement p3:=convert(s3, polynom) converts the series s3 to the polynomial p3 by dropping the remainder. To obtain 11 decimal digits of display, we enter

Digits:=11;

and evaluate f (0.01), P 3 (0.01), and |f (0.01) − P 3 (0.01)| with

y1:=evalf(subs(x=0.01,f)); y2:=evalf(subs(x=0.01,p3)); err:=abs(y1-y2);

This produces y 1 = f (0.01) = 0.99995000042, y 2 = P 3 (0.01) = 0.99995000000, and |f (0.01) − P 3 (0.01)| =. 42 × 10 −^9. To obtain a graph similar to Figure 1.8, enter

plot({f,p3},x=-Pi..Pi);

The commands for the integrals are

q1:=int(f,x=0..0.1); q2:=int(p3,x=0..0.1); err:=abs(q1-q2);

which give the values

q 1 =

0

f (x) dx = 0. 099833416647 and q 2 =

0

P 3 (x) dx = 0. 099833333333 ,

with error 0. 83314 × 10 −^7 = 8. 3314 × 10 −^8. Parts (a) and (b) of Example 3 show how two techniques can produce the same approximation but have differing accuracy assurances. Remember that determining approximations is only part of our objective. The equally important other part is to determine at least a bound for the accuracy of the approximation.

14 CHAPTER 1. MATHEMATICAL PRELIMINARIES AND ERROR ANALYSIS

EXERCISE SET 1.

  1. Show that the following equations have at least one solution in the given intervals.

(a) x cos x − 2 x^2 + 3x − 1 = 0, [0. 2 , 0 .3] and [1. 2 , 1 .3] (b) (x − 2)^2 − ln x = 0, [1, 2] and [e, 4] (c) 2x cos(2x) − (x − 2)^2 = 0, [2, 3] and [3, 4] (d) x − (ln x)x^ = 0, [4, 5]

  1. Find intervals containing solutions to the following equations.

(a) x − 3 −x^ = 0 (b) 4x^2 − ex^ = 0 (c) x^3 − 2 x^2 − 4 x + 3 = 0 (d) x^3 + 4. 001 x^2 + 4. 002 x + 1.101 = 0

  1. Show that the first derivatives of the following functions are zero at least once in the given intervals.

(a) f (x) = 1 − ex^ + (e − 1) sin((π/2)x), [0, 1] (b) f (x) = (x − 1) tan x + x sin πx, [0, 1] (c) f (x) = x sin πx − (x − 2) ln x, [1, 2] (d) f (x) = (x − 2) sin x ln(x + 2), [− 1 , 3]

  1. Find maxa≤x≤b |f (x)| for the following functions and intervals.

(a) f (x) = (2 − ex^ + 2x)/ 3 , [0, 1] (b) f (x) = (4x − 3)/(x^2 − 2 x), [0. 5 , 1] (c) f (x) = 2x cos(2x) − (x − 2)^2 , [2, 4] (d) f (x) = 1 + e−^ cos(x−1), [1, 2]

  1. Let f (x) = x^3.

(a) Find the second Taylor polynomial P 2 (x) about x 0 = 0. (b) Find R 2 (0.5) and the actual error when using P 2 (0.5) to approximate f (0.5). (c) Repeat part (a) with x 0 = 1. (d) Repeat part (b) for the polynomial found in part (c).

  1. Let f (x) =

x + 1.

(a) Find the third Taylor polynomial P 3 (x) about x 0 = 0. (b) Use P 3 (x) to approximate

1 .25, and

16 CHAPTER 1. MATHEMATICAL PRELIMINARIES AND ERROR ANALYSIS

  1. The nth Taylor polynomial for a function f at x 0 is sometimes referred to as the polynomial of degree at most n that “best” approximates f near x 0.

(a) Explain why this description is accurate. (b) Find the quadratic polynomial that best approximates a function f near x 0 = 1 if the tangent line at x 0 = 1 has equation y = 4x − 1, and if f ′′(1) = 6.

  1. The error function defined by

erf(x) =

π

∫ (^) x

0

e−t

2 dt

gives the probability that any one of a series of trials will lie within x units of the mean, assuming that the trials have a normal distribution with mean 0 and standard deviation

2 /2. This integral cannot be evaluated in terms of elementary functions, so an approximating technique must be used.

(a) Integrate the Maclaurin series for e−t 2 to show that

erf(x) =

π

∑^ ∞

k=

(−1)kx^2 k+ (2k + 1)k!

(b) The error function can also be expressed in the form

erf(x) =

π

e−x

2

∑^ ∞

k=

2 kx^2 k+ 1 · 3 · 5 · · · (2k + 1)

Verify that the two series agree for k = 1, 2, 3, and 4. [Hint: Use the Maclaurin series for e−x 2 .] (c) Use the series in part (a) to approximate erf(1) to within 10−^7. (d) Use the same number of terms used in part (c) to approximate erf(1) with the series in part (b). (e) Explain why difficulties occur using the series in part (b) to approximate erf(x).

1.3. ROUND-OFF ERROR AND COMPUTER ARITHMETIC 17

1.3 Round-off Error and Computer Arithmetic

The arithmetic performed by a calculator or computer is different from the arith- metic that we use in our algebra and calculus courses. From your past experience you might expect that we always have as true statements such things as 2 + 2 = 4, 4 · 8 = 32, and (

3)^2 = 3. In standard computational arithmetic we expect exact results for 2 + 2 = 4 and 4 · 8 = 32, but we will not have precisely (

3)^2 = 3. To understand why this is true we must explore the world of finite-digit arithmetic.

In our traditional mathematical world we permit numbers with an infinite num- ber of digits. The arithmetic we use in this world defines

3 as that unique positive number that when multiplied by itself produces the integer 3. In the computational world, however, each representable number has only a fixed and finite number of digits. This means, for example, that only rational numbers—and not even all of these—can be represented exactly. Since

3 is not rational, it is given an approx- imate representation within the machine, a representation whose square will not be precisely 3, although it will likely be sufficiently close to 3 to be acceptable in most situations. In most cases, then, this machine representation and arithmetic is satisfactory and passes without notice or concern, but at times problems arise because of this discrepancy.

The error that is produced when a calculator or computer is used to perform real-number calculations is called round-off error. It occurs because the arithmetic performed in a machine involves numbers with only a finite number of digits, with the result that calculations are performed with only approximate representations of the actual numbers. In a typical computer, only a relatively small subset of the real number system is used for the representation of all the real numbers. This subset contains only rational numbers, both positive and negative, and stores the fractional part, together with an exponential part.

In 1985, the IEEE (Institute for Electrical and Electronic Engineers) published a report called Binary Floating Point Arithmetic Standard 754–1985. Formats were specified for single, double, and extended precisions. These standards are generally followed by all microcomputer manufacturers using hardware that performs real- number, or floating point, arithmetic operations. For example, the double precision real numbers require a 64-bit (binary digit) representation.

The first bit is a sign indicator, denoted s. This is followed by an 11-bit exponent, c, and a 52-bit binary fraction, f , called the mantissa. The base for the exponent is 2.

The normalized form for the nonzero double precision numbers have 0 < c < 211 − 1 = 2047. Since c is positive, a bias of 1023 is subtracted from c to give an actual exponent in the interval (− 1023 , 1024). This permits adequate representation of numbers with both large and small magnitude.The first bit of the fractional part of a number is assumed to be 1 and is not stored in order to give one additional bit of precision to the representation, Since 53 binary digits correspond to between 15 and 16 decimal digits, we can assume that a number represented using this system has at least 15 decimal digits of precision. Thus, numbers represented in normalized

1.3. ROUND-OFF ERROR AND COMPUTER ARITHMETIC 19

Numbers occurring in calculations that have too small a magnitude to be repre- sented result in underflow, and are generally set to 0 with computations contin- uing. However, numbers occurring in calculations that have too large a magnitude to be represented result in overflow and typically cause the computations to stop (unless the program has been designed to detect this occurrence). Note that there are two representations for the number zero; a positive 0 when s = 0, c = 0 and f = 0 and a negative 0 when s = 1, c = 0 and f = 0. The use of binary digits tends to complicate the computational problems that occur when a finite collection of machine numbers is used to represent all the real numbers. To examine these problems, we now assume, for simplicity, that machine numbers are represented in the normalized decimal form

± 0 .d 1 d 2... dk × 10 n, 1 ≤ d 1 ≤ 9 , 0 ≤ di ≤ 9

for each i = 2,... , k. Numbers of this form are called k-digit decimal machine numbers. Any positive real number within numerical range of the machine can be nor- malized to achieve the form

y = 0.d 1 d 2... dkdk+1dk+2... × 10 n.

The floating-point form of y, denoted by f l(y), is obtained by terminating the mantissa of y at k decimal digits. There are two ways of performing the termination. One method, called chopping, is to simply chop off the digits dk+1dk+2... to obtain

f l(y) = 0.d 1 d 2... dk × 10 n.

The other method of terminating the mantissa of y at k decimal points is called rounding. If the k + 1st digit is smaller than 5, then the result is the same as chopping. If the k + 1st digit is 5 or greater, then 1 is added to the kth digit and the resulting number is chopped. As a consequence, rounding can be accomplished by simply adding 5 × 10 n−(k+1)^ to y and then chopping the result to obtain f l(y). Note that when rounding up the exponent n could increase by 1. In summary, when rounding we add one to dk to obtain f l(y) whenever dk+1 ≥ 5, that is, we round up; when dk+1 < 5, we chop off all but the first k digits, so we round down. The next examples illustrate floating-point arithmetic when the number of digits being retained is quite small. Although the floating-point arithmetic that is per- formed on a calculator or computer will retain many more digits, the problems this arithmetic can cause are essentially the same regardless of the number of digits. Retaining more digits simply postpones the awareness of the situation.

EXAMPLE 1 The irrational number π has an infinite decimal expansion of the form π = 3. 14159265.... Written in normalized decimal form, we have

π = 0. 314159265... × 101.

The five-digit floating-point form of π using chopping is

f l(π) = 0. 31415 × 101 = 3. 1415.

20 CHAPTER 1. MATHEMATICAL PRELIMINARIES AND ERROR ANALYSIS

Since the sixth digit of the decimal expansion of π is a 9, the five-digit floating-point form of π using rounding is

f l(π) = (0.31415 + 0.00001) × 101 = 0. 31416 × 101 = 3. 1416.

The error that results from replacing a number with its floating-point form is called round-off error (regardless of whether the rounding or chopping method is used). There are two common methods for measuring approximation errors. The approximation p∗^ to p has absolute error |p − p∗| and relative error |p − p∗|/|p|, provided that p = 0.

EXAMPLE 2 a.If p = 0. 3000 × 101 and p∗^ = 0. 3100 × 101 , the absolute error is 0.1 and the relative error is 0. 3333 × 10 −^1.

b.If p = 0. 3000 × 10 −^3 and p∗^ = 0. 3100 × 10 −^3 , the absolute error is 0. 1 × 10 −^4 , but the relative error is again 0. 3333 × 10 −^1.

c.If p = 0. 3000 × 104 and p∗^ = 0. 3100 × 104 , the absolute error is 0. 1 × 103 , but the relative error is still 0. 3333 × 10 −^1.

This example shows that the same relative error can occur for widely varying absolute errors. As a measure of accuracy, the absolute error can be misleading and the relative error is more meaningful, since the relative error takes into consideration the size of the true value.

The arithmetic operations of addition, subtraction, multiplication, and division performed by a computer on floating-point numbers also introduce error. These arithmetic operations involve manipulating binary digits by various shifting and logical operations, but the actual mechanics of the arithmetic are not pertinent to our discussion. To illustrate the problems that can occur, we simulate this finite- digit arithmetic by first performing, at each stage in a calculation, the appropriate operation using exact arithmetic on the floating-point representations of the num- bers. We then convert the result to decimal machine-number representation. The most common round-off error producing arithmetic operation involves the subtrac- tion of nearly equal numbers.

EXAMPLE 3 Suppose we use four-digit decimal chopping arithmetic to simulate the problem of performing the computer operation π − 227. The floating-point representations of these numbers are

f l(π) = 0. 3141 × 101 and f l

= 0. 3142 × 101.

Performing the exact arithmetic on the floating-point numbers gives

f l(π) − f l

= − 0. 0001 × 101 ,