Chapter 1 Computer Arithmetic

Similar documents
Chapter 1 Mathematical Preliminaries and Error Analysis

Computer Arithmetic. MATH 375 Numerical Analysis. J. Robert Buchanan. Fall Department of Mathematics. J. Robert Buchanan Computer Arithmetic

AIMS Lecture Notes 2006

Lecture 7. Floating point arithmetic and stability

ACM 106a: Lecture 1 Agenda

Jim Lambers MAT 610 Summer Session Lecture 2 Notes

Notes for Chapter 1 of. Scientific Computing with Case Studies

Mathematical preliminaries and error analysis

Math 411 Preliminaries

Arithmetic and Error. How does error arise? How does error arise? Notes for Part 1 of CMSC 460

Numerical Methods. King Saud University

Introduction CSE 541

CME 302: NUMERICAL LINEAR ALGEBRA FALL 2005/06 LECTURE 5. Ax = b.

Floating Point Number Systems. Simon Fraser University Surrey Campus MACM 316 Spring 2005 Instructor: Ha Le

Mathematics for Engineers. Numerical mathematics

Numerical Analysis and Computing

Binary floating point

EAD 115. Numerical Solution of Engineering and Scientific Problems. David M. Rocke Department of Applied Science

PowerPoints organized by Dr. Michael R. Gustafson II, Duke University

Numerical Analysis. Yutian LI. 2018/19 Term 1 CUHKSZ. Yutian LI (CUHKSZ) Numerical Analysis 2018/19 1 / 41

NUMERICAL MATHEMATICS & COMPUTING 6th Edition

Compute the behavior of reality even if it is impossible to observe the processes (for example a black hole in astrophysics).

Number Systems III MA1S1. Tristan McLoughlin. December 4, 2013

MAT 460: Numerical Analysis I. James V. Lambers

Floating-point Computation

Notes on floating point number, numerical computations and pitfalls

AIMS Exercise Set # 1

Introduction and mathematical preliminaries

Tu: 9/3/13 Math 471, Fall 2013, Section 001 Lecture 1

Numerical Methods - Preliminaries

Errors. Intensive Computation. Annalisa Massini 2017/2018

Chapter 1: Introduction and mathematical preliminaries

Lecture Notes 7, Math/Comp 128, Math 250

FLOATING POINT ARITHMETHIC - ERROR ANALYSIS

CS 450 Numerical Analysis. Chapter 8: Numerical Integration and Differentiation

Introduction to Numerical Analysis

FLOATING POINT ARITHMETHIC - ERROR ANALYSIS

ECS 231 Computer Arithmetic 1 / 27

Chapter 1 Error Analysis

The Gram-Schmidt Process

Introduction to Finite Di erence Methods

Elements of Floating-point Arithmetic

MITOCW watch?v=y6ma-zn4olk

1 Floating point arithmetic

Chapter 1: Preliminaries and Error Analysis

QUADRATIC PROGRAMMING?

THE TEACHER UNDERSTANDS THE REAL NUMBER SYSTEM AND ITS STRUCTURE, OPERATIONS, ALGORITHMS, AND REPRESENTATIONS

Elements of Floating-point Arithmetic

ALGEBRA+NUMBER THEORY +COMBINATORICS

What Every Programmer Should Know About Floating-Point Arithmetic DRAFT. Last updated: November 3, Abstract

NUMERICAL METHODS C. Carl Gustav Jacob Jacobi 10.1 GAUSSIAN ELIMINATION WITH PARTIAL PIVOTING

Lecture 28 The Main Sources of Error

ABE Math Review Package

Numerical Methods. King Saud University

THE TEACHER UNDERSTANDS THE REAL NUMBER SYSTEM AND ITS STRUCTURE, OPERATIONS, ALGORITHMS, AND REPRESENTATIONS

Applied Mathematics 205. Unit 0: Overview of Scientific Computing. Lecturer: Dr. David Knezevic

Infinite series, improper integrals, and Taylor series

Numerical Methods. Dr Dana Mackey. School of Mathematical Sciences Room A305 A Dana Mackey (DIT) Numerical Methods 1 / 12

Numerical Algorithms. IE 496 Lecture 20

What are Numerical Methods? (1/3)

A Method for Reducing Ill-Conditioning of Polynomial Root Finding Using a Change of Basis

Deep Learning. Authors: I. Goodfellow, Y. Bengio, A. Courville. Chapter 4: Numerical Computation. Lecture slides edited by C. Yim. C.

Numerical Methods in Physics and Astrophysics

THE TEACHER UNDERSTANDS THE REAL NUMBER SYSTEM AND ITS STRUCTURE, OPERATIONS, ALGORITHMS, AND REPRESENTATIONS

Scientific Computing: An Introductory Survey

ESO 208A: Computational Methods in Engineering. Saumyen Guha

Next, we include the several conversion from type to type.

Chapter 1. Numerical Errors. Module No. 1. Errors in Numerical Computations

Computing Machine-Efficient Polynomial Approximations

Lies My Calculator and Computer Told Me

ter. on Can we get a still better result? Yes, by making the rectangles still smaller. As we make the rectangles smaller and smaller, the

Analysis of Finite Wordlength Effects

4.2 Floating-Point Numbers

Taylor series. Chapter Introduction From geometric series to Taylor polynomials

Power series and Taylor series

Chapter 1 Mathematical Preliminaries and Error Analysis

How do computers represent numbers?

1.1 COMPUTER REPRESENTATION OF NUM- BERS, REPRESENTATION ERRORS

A. Incorrect! Check your algebra when you solved for volume. B. Incorrect! Check your algebra when you solved for volume.

27 Wyner Math 2 Spring 2019

Properties of Rational and Irrational Numbers

MATH Dr. Halimah Alshehri Dr. Halimah Alshehri

Chaos and Liapunov exponents

Lecture Notes to Accompany. Scientific Computing An Introductory Survey. by Michael T. Heath. Chapter 9

Take the measurement of a person's height as an example. Assuming that her height has been determined to be 5' 8", how accurate is our result?

AP Calculus Chapter 9: Infinite Series

8.3 Partial Fraction Decomposition

ALU (3) - Division Algorithms

POWER ALGEBRA NOTES: QUICK & EASY

CHAPTER 11. A Revision. 1. The Computers and Numbers therein

Uncertainty, Error, and Precision in Quantitative Measurements an Introduction 4.4 cm Experimental error

NUMERICAL METHODS. x n+1 = 2x n x 2 n. In particular: which of them gives faster convergence, and why? [Work to four decimal places.

CHAPTER 10 Zeros of Functions

8.5 Taylor Polynomials and Taylor Series

CSE 20 DISCRETE MATH. Fall

Zeros of Functions. Chapter 10

1.1.1 Algebraic Operations

Linear algebra for MATH2601 Numerical methods

Introductory Quantum Chemistry Prof. K. L. Sebastian Department of Inorganic and Physical Chemistry Indian Institute of Science, Bangalore

PHY411 Lecture notes Part 5

Transcription:

Numerical Analysis (Math 9372) 2017-2016 Chapter 1 Computer Arithmetic 1.1 Introduction Numerical analysis is a way to solve mathematical problems by special procedures which use arithmetic operations only. A major advantage for numerical analysis is that a numerical answer can be obtained even when a problem has no analytical solution. The main goal of numerical analysis is developing and analyzing efficient algorithms for computing precise numerical solutions to problems. Algorithms are implemented via computer programs and are studied to provide insight into their behavior, such as convergence rates and forward or backward error analysis. The goal of this course is to introduce some of the most important and basic numerical algorithms that are used in practical computations. In addition to learning the basic techniques, it is crucial to develop a thorough understanding of how the algorithms are constructed, why they work, and what their limitations are. Problems solvable by numerical analysis The following problems are some of the mathematical problems that can be solved using numerical analysis: (1) Solving scalar nonlinear equations. (2) Solving large systems of linear equations. (3) Solving systems of nonlinear equations. (4) Interpolating to find intermediate values within a table of data. (5) Fitting curves to data by a variety of methods. (6) Finding efficient and effective approximations of functions. (7) Finding derivatives of any order for functions even when the function is known only as a table of values. (8) Integrating any function even when known only as a table of values. (9) Solving differential equations. (10) Finding eigenvalues and eigenvectors of a matrix. 1

Example 1. The equation e x + sin x = 0 has no analytic solution but it can be solved numerically. Example 2. The integral b a e x2 dx has no closed solution but it can be evaluated numerically. Differences between numerical and analytic methods (1) Numerical solution is always numerical while analytic solution is given in terms of functions. Thus analytic solution has the advantage that it can be evaluated for specific instance and behavior and properties of the solution are often apparent. (2) Analytic methods give exact solutions while numerical methods give approximate solutions. Computer and numerical analysis Computer and numerical analysis make a perfect combination. Numerical methods require such tedious and repetitive arithmetic operations that only when we use computer it is practical to solve problems by numerical methods. A human would make so many mistakes that there would be little confidence in the result. In addition, the manpower cost would be more than could normally be afforded. To use computers in numerical analysis we must write computer programs. The computer language is not important; one can use any language. Actually, writing programs is not always necessary. Numerical analysis is so important that extensive commercial software packages are available. An alternative to using a program written in one of the computer languages is to use a kind of software sometimes called a symbolic algebra program. These programs mimic the way the humans solve mathematical problems. Many such symbolic programs are available including FreeMat, Mathematica, Derive, MAPLE. MathCad, MATLAB, and MacSyma. 1.2 Computer arithmetic and errors As we said before, numerical methods give approximated solutions. In order to control how good are these approximations we need to control the error in them. In any applied numerical computation, there are four key sources of error: (i) Inexactness of the mathematical model for the underlying physical phenomenon. (ii) Errors in measurements of parameters entering the model. (iii) Round-off errors in computer arithmetic. (iv) Approximations used to solve the full mathematical system. Of these, (i) is the domain of mathematical modeling, and will not concern us here. Neither will (ii), which is the domain of the experimentalists. (iii) arises due to the finite numerical precision imposed by the computer. (iv) is the true domain of numerical analysis, and refers to the fact that most systems of equations are too complicated to solve explicitly, or, even in cases when an analytic solution formula is known, directly obtaining the precise numerical values may be difficult. 2

Absolute and relative errors There are common ways to express the size of the error in a computed result: absolute error and relative error. Definition. (Absolute and relative errors) Let x be an approximation to the real number x. 1. The absolute error in the approximation x x is E a = x x. 2. If x 0, then the relative error in the approximation x x is E r = x x x. Remark. 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. Significant digits Significant digits is another way to express accuracy (how good an approximation is). It controls how many digit in the number have meaning after normalization. We will say that an approximation x has k significant decimal digits if its relative error is E r < 5 10 k 1. This means that the first k digits of x following its first nonzero digit are the same as those of x. Example 1. Let x = 15.4321 and x = 15.4318. Then E r = 0.0000194399 < 5 10 5 and hence, x and x agree to 4 significant digits. Example 2. Let x = 0.0123 and x = 0.0129. Then E r = 0.048704 < 5 10 2. Therefore, x and x agree to 1 significant digit. Remark. In general, the true value will not be known. Thus, we can not use E a and E r to control numerical methods. We will use approximated error to over come this problem. Floating-point numbers We use computers to implement numerical algorithms. A most unfortunate fact of life is that all digital computers, no matter how super, can only store finitely many quantities. Thus, there is no way that a computer can represent the (discrete) infinity of all integers or all rational numbers, let alone the (continuous) infinity of all real or all complex numbers. So the decision of how to approximate more general numbers using only the finitely many that the computer can handle becomes of critical importance. Each number in a computer is assigned a location or word, consisting of a specified number of binary digits or bits. In a binary system, a k bit word can store a total of N = 2 k different ( 1 numbers 2 N positive numbers and 1 N negative numbers). The set of real numbers in a computer 2 is R c = {x 1, x 2,..., x N }. For example, the standard single precision computer uses 32 bit arithmetic, for a total of N = 2 32 4.3 10 9 different numbers, while double precision uses 64 bits, with N = 2 64 1.84 10 19 3

different numbers. The question is how to distribute the N exactly representable numbers over the real line for maximum efficiency and accuracy in practical computations. One evident choice is to distribute them evenly, leading to fixed point arithmetic. For example, one can use the first bit in a word to represent a sign, and treat the remaining bits as integers, thereby representing the integers from 1 1 2 N = 1 2k 1 to 1 2 N = 2k 1 exactly. (R c = {x 1, x 2,..., x N 1 } = { 1 2 k 1, 2 2 k 1,..., 2 k 1} ) Of course, this does a poor job approximating most non-integral numbers. Another option is to space the numbers closely together, say with uniform gap of 2 n, and so distribute our N numbers uniformly over the interval 2 n 1 N < x 2 n 1 N. (R c = {x 1, x 2,..., x N 1 } = { 2 n (1 2 k 1 ), 2 n (2 2 k 1 ),..., 2 n+k 1} ) Real numbers lying between the gaps are represented by either rounding, meaning the closest exact representative, or chopping, meaning the exact representative immediately below (or above if negative) the number. Numbers lying beyond the range must be represented by the largest (or largest negative) representable number, which thus becomes a symbol for overflow. When processing speed is a significant bottleneck, the use of such fixed point representations is an attractive and faster alternative to the more cumbersome floating point arithmetic most commonly used in practice. The most common non-uniform distribution of our N numbers is the floating point system, which is based on scientific notation. If x is any real number it can be written in the form x = ±.d 1 d 2 d 3... d p B e, where the d i s are digits or bits with 0 d i B 1 and B =the number base that is used, usually 2 (binary), 8 (octal), 10 (decimal), or 16 (hexadecimal). Base 10 is often found on hand-held calculators but rarely in fully programmable computers. p =the number of significant bits (digits), that is, the precision. e =an integer exponent, ranging from e min to e max, with values going from negative e min to positive e max. In almost all cases, numbers are normalized so that d 1 0. Floating-point numbers have three parts sign: ±, mantissa (fractional part): d 1 d 2 d p, exponent part (characteristic): B e. The three parts have fixed total length 32 or 64 bits. The mantissa use most of these bits (23-52). The number of the bits that is used by the mantissa determines the precision of the representation and the bits of the exponent determines the range of the values. Most computer permits two or even three types of numbers: (1) In single precision floating point arithmetic, the sign is 1 bit, the exponent is 7 bits, and the mantissa is 24 bits. The resulting nonzero numbers lie in the range 2 127 10 38 x 2 127 10 38, and allow one to accurately represent numbers with approximately 7 significant decimal digits of real numbers lying in this range. 4

(2) In double precision floating point arithmetic, the sign is 1 bit, the exponent is 10 bits, and the mantissa is 53 bits, leading to floating point representations for a total of 1.84 10 19 different numbers which, apart from 0. The resulting nonzero numbers lie in the range 2 1023 10 308 x 2 1023 10 308. In double precision, one can accurately represent approximately 15 decimal digits. (3) Extended precision: 19 to 20 significant decimal digits (±.d 1 d 20 B e ). Keep in mind floating point numbers are not uniformly spaced! Moreover, when passing from.111111... 2 n to.100000... 2 n+1, the inter-number spacing suddenly jumps by a factor of 2. The non-smoothly varying spacing inherent in the floating point system can cause subtle, undesirable numerical artifacts in high precision computations. Any positive real number within numerical range of the machine can be normalized to achieve the form x = 0.d 1 d 2 d k d k+1 d k+2 B n. The floating-point form of x is obtained by terminating the mantissa of x at k decimal digits x x = 0.d 1 d 2 d k B n. There are two ways of performing the termination. One method, called chopping, is to simply chop off the digits d k+1 d k+2. The other method of terminating the mantissa of x 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. Overflow and underflow Very small numbers, lying in the gap between 0 < x < B e min, are said to cause underflow. They are generally set to 0 with computations continuing. However, numbers occurring in calculations that have too large magnitude to be represented result in overflow and typically cause the computations to stop (unless the program has been designed to detect this occurrence). Floating-point arithmetic In the course of a calculation, intermediate errors interact in a complex fashion, and result in a final total error that is not just the sum of the individual errors. If x is an approximation to x, and y is an approximation to y, then, instead of arithmetic operations +,,, / and so on, the computer uses a pseudo-operations to combine them. For instance, to approximate the difference x y of two real numbers, the computer begins by replacing each by its floating point approximation x and y. It then subtracts these, and replaces the exact result x y by its nearest floating point representative, namely (x y ). As the following example makes clear, this is not necessarily the same as the floating point approximation to x y, i.e., in general (x y ) (x y). Example. Lets see what happens if we subtract the rational numbers x = 301 301 0.15050000..., y = 2000 2001 0.150424787... 5

The exact answer is x y = 301 0.00007521239... However, if we use rounding to approximate 4002000 with 4 significant digits, then x = 301 301 0.1505, y = 0.1504 and so x y 0.0001, 2000 2001 which has no significant digits in common with the actual answer. On the other hand, if we evaluate the difference using the alternative formula x y = 301 2001 301 2000 4002000 = 6.023 105 6.020 10 5 4.002 10 6 = 602301 602000 4002000.003 105 4.002 10.00007496, 6 we at least reproduce the first two significant digits. Thus, the result of a floating point computation depends on the order of the arithmetic operations! In particular, the associative and distributive laws are not valid in floating point arithmetic! In the development of numerical analysis, one tends to not pay attention to this minor detail, although its effects must always be kept in the back of ones mind when evaluating the results of any serious numerical computation. Just in case you are getting a little complacent, thinking gee, a few tiny round off errors can not really make that big difference, let us close with two cautionary examples. Example 1. Consider the pair of degree 10 polynomials and p(x) = (x 1)(x 2)(x 3)(x 4)(x 5)(x 6)(x 7)(x 8)(x 9)(x 10) q(x) = p(x) + x 5. They only differ in the value of the coefficient of their middle term, which, by a direct expansion, is 902055x 5 in p(x), and 902054x 5 in q(x); all other terms are the same. The relative error between the two coefficients is roughly one-thousandth of one percent. Our task is to compute the roots of these two polynomials, i.e., the solutions to p(x) = 0 and q(x) = 0. Those of p(x) are obvious. One might expect the roots of q(x) to be rather close to the integers 1, 2,..., 10. However, their approximate values are 1.0000027558, 1.99921, 3.02591, 3.82275, 5.24676 ± 0.751485i, 7.57271 ± 1.11728i, 9.75659 ± 0.368389i. Surprisingly, only the smallest two roots are relatively unchanged; the third and fourth roots differ by roughly 1% and 27%, while the final six roots have mysteriously metamorphosed into three complex conjugate pairs of roots of q(x). We have thus learned that an almost negligible change in a single coefficient of a real polynomial can have dramatic and unanticipated effects on its roots. Needless to say, this indicates that finding accurate numerical values for the roots of high degree polynomials is a very challenging problem. Example 2. Consider the initial value problem The solution is easily found: du dt 2u = e t, u(0) = 1 3. u(t) = 1 3 e t, and is exponentially decaying as t. 6

However, in a floating point computer, we are not able to represent the initial condition 1 3 exactly, and make some small round-off error (depending on the precision of the computer). Let ɛ 0 represent the error in the initial condition. The solution to the perturbed initial value is dv dt 2v = e t, v(0) = 1 3 + ɛ, v(t) = 1 3 e t + ɛe 2t, which is exponentially growing as t increases. Figure 1: As sketched in Figure 1, the two solutions remain close only for a very short time interval, the duration of which depends on the size in the initial error, but then they eventually diverge far away from each other. As a consequence, a tiny error in the initial data can have a dramatic effect on the solution. This phenomenon is referred to as sensitive dependence on initial conditions. The numerical computation of the exponentially decaying exact solution in the face of round-off errors is an extreme challenge. Even the tiniest of error will immediately introduce an exponentially growing mode which will eventually swamp the true solution. Furthermore, in many important applications, the physically relevant solution is the one that decays to zero at large distances, and is usually distinguished from the vast majority of solutions that grow at large distances. So the computational problem is both important and very difficult. Examples 1 and 2 are known as ill-conditioned problems meaning that tiny changes in the data have dramatic effects on the solutions. Simple numerical methods work as advertised on wellconditioned problems, but all have their limitations and a sufficiently ill-conditioned problem will test the limits of the algorithm and/or computer, and, in many instances, require revamping a standard numerical solution scheme to adapt to the ill-conditioning. Some problems are so ill-conditioned as 7

to defy even the most powerful computers and sophisticated algorithms. For this reason, numerical analysis will forever remain a vital and vibrant area of mathematical research. So, numerical analysis cannot be viewed in isolation as a black box, and left in the hands of the mathematical experts. Every practitioner will, sooner or later, confront a problem that tests the limitations of standard algorithms and software. Without a proper understanding of the mathematical principles involved in constructing basic numerical algorithms, one is ill-equipped, if not hopelessly handicapped, when dealing with such problems. The purpose of this course is to give you the proper mathematical grounding in modern numerical analysis. References [1] Olver, P. J. (2006). AIMS lecture notes on numerical analysis. 8