Introduction to Scientific Computing

Similar documents
Lecture 7. Floating point arithmetic and stability

1.1 COMPUTER REPRESENTATION OF NUM- BERS, REPRESENTATION ERRORS

Chapter 1: Introduction and mathematical preliminaries

Notes for Chapter 1 of. Scientific Computing with Case Studies

Chapter 1 Error Analysis

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

Jim Lambers MAT 610 Summer Session Lecture 2 Notes

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

Mathematical preliminaries and error analysis

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

Numerical Methods - Preliminaries

Notes on floating point number, numerical computations and pitfalls

ECS 231 Computer Arithmetic 1 / 27

Lecture 1. Introduction to Numerical Methods. T. Gambill. Department of Computer Science University of Illinois at Urbana-Champaign.

FLOATING POINT ARITHMETHIC - ERROR ANALYSIS

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

Can You Count on Your Computer?

Round-off Errors and Computer Arithmetic - (1.2)

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

FLOATING POINT ARITHMETHIC - ERROR ANALYSIS

Introduction and mathematical preliminaries

Models. Representing models. Basic Data Types

1 ERROR ANALYSIS IN COMPUTATION

How do computers represent numbers?

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

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

Who am I? Math 1080: Numerical Linear Algebra. Books. Format

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

Solutions to Assignment 1

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

Elements of Floating-point Arithmetic

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

Chapter 1 Mathematical Preliminaries and Error Analysis

Applied Numerical Analysis (AE2220-I) R. Klees and R.P. Dwight

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

ESTIMATION OF ERROR. r = b Abx a quantity called the residual for bx. Then

Math 31 Lesson Plan. Day 2: Sets; Binary Operations. Elizabeth Gillaspy. September 23, 2011

Chapter 1 Computer Arithmetic

Numerical Analysis and Computing

Elements of Floating-point Arithmetic

Chapter 4 Number Representations

Linear algebra for MATH2601 Numerical methods

Chapter 1: Preliminaries and Error Analysis

MATH2071: LAB #5: Norms, Errors and Condition Numbers

Floating-point Computation

Abstract. Ariane 5. Ariane 5, arithmetic overflow, exact rounding and Diophantine approximation

Binary floating point

QUADRATIC PROGRAMMING?

An Introduction to Differential Algebra

FALL 2018 MATH 4211/6211 Optimization Homework 4

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

1 Floating point arithmetic

Order of convergence. MA3232 Numerical Analysis Week 3 Jack Carl Kiefer ( ) Question: How fast does x n

Introduction to Scientific Computing Languages

Introduction to Numerical Analysis

Lecture 1: Introduction to computation

CS412: Introduction to Numerical Methods

Introduction to Scientific Computing Languages

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

MATH ASSIGNMENT 03 SOLUTIONS

Mathematics for Engineers. Numerical mathematics

4.2 Floating-Point Numbers

then kaxk 1 = j a ij x j j ja ij jjx j j: Changing the order of summation, we can separate the summands, kaxk 1 ja ij jjx j j: let then c = max 1jn ja

MATH20602 Numerical Analysis 1

1 What is numerical analysis and scientific computing?

MATH20602 Numerical Analysis 1

CSE 20 DISCRETE MATH. Fall

Representing Numbers on the Computer

ORF 363/COS 323 Final Exam, Fall 2018

Numerical Derivatives in Scilab

Introduction CSE 541

8 Square matrices continued: Determinants

An Introduction to Numerical Analysis. James Brannick. The Pennsylvania State University

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

Today s Lecture. Mars Climate Orbiter. Lecture 21: Software Disasters. Mars Climate Orbiter, continued

8.5 Taylor Polynomials and Taylor Series

Midterm Exam Information Theory Fall Midterm Exam. Time: 09:10 12:10 11/23, 2016

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

ECE 204 Numerical Methods for Computer Engineers MIDTERM EXAMINATION /8:00-9:30

2.29 Numerical Fluid Mechanics Fall 2011 Lecture 2

Errors. Intensive Computation. Annalisa Massini 2017/2018

Ex code

1 Problem 1 Solution. 1.1 Common Mistakes. In order to show that the matrix L k is the inverse of the matrix M k, we need to show that

Math 128A: Homework 2 Solutions

Math 1600B Lecture 4, Section 2, 13 Jan 2014

HOMEWORK 8 SOLUTIONS MATH 4753

Numerical Computation for Deep Learning

ACM 106a: Lecture 1 Agenda

Math 411 Preliminaries

CSE 20 DISCRETE MATH. Fall

Lecture 5. September 4, 2018 Math/CS 471: Introduction to Scientific Computing University of New Mexico

Numerical Methods for Ordinary Differential Equations. C. Vuik F.J. Vermolen M.B. van Gijzen M.J. Vuik

Bindel, Fall 2011 Intro to Scientific Computing (CS 3220) Week 3: Wednesday, Jan 9

Numerical Algorithms. IE 496 Lecture 20

Numerical Mathematical Analysis

Instructors Manual Algebra and Trigonometry, 2e Cynthia Y. Young

Main topics for the First Midterm Exam

Math 348: Numerical Methods with application in finance and economics. Boualem Khouider University of Victoria

Notes on Conditioning

Transcription:

(Lecture 2: Machine precision and condition number) B. Rosić, T.Moshagen Institute of Scientific Computing

General information :) 13 homeworks (HW) Work in groups of 2 or 3 people Each HW brings maximally 36 points =468 points Exam requirement: > 50% or approx. 234 points Please, do not copy or you will get 0 points!!! Assignments and other information you may find on web-page: https://www.tu-braunschweig.de/wire/lehre/ws15/ode1 Open office hours: Dr. Moshagen, Wednesday, 14:00-15:00 Dr. Liu (make appointment) 2 / 44

General information :) You are allowed to program in: Matlab (Octave), python (NumPy). We recommend Matlab (Octave) as easiest for the beginnin All program codes have to be suploaded to your groups studip directory Other things than code in paper (don t forget to write your student ID and name) HW submit on tutorials ( deadline: each next Friday before exercises) 3 / 44

HW format 4 / 44

HW format 5 / 44

HW format Function has to be written in a separate file. Function file has to be followed by main file Do not send only function file! Plot results!! Send all plots attached! 6 / 44

I Motivation for today s lecture: Ariane 5 Ariane 5 rockets are manufactured under the authority of the European Space Agency (ESA) and the Centre National d Etudes Spatiales. Airbus Defence and Space is the prime contractor for the vehicles, leading a consortium of subcontractors. Ariane 5 is operated and marketed by Arianespace as part of the Ariane programme. Astrium builds the rockets in Europe and Arianespace launches them from the Guiana Space Centre in French Guiana. Total cost: $500 million Time of development: a decade @stff.co.uk 7 / 44

and ca. 40 seconds later... @esa On 4 June 1996, the maiden flight of the Ariane 5 launcher ended in a failure. Only about 40 seconds after initiation of the flight sequence, at an altitude of about 3700 m, the launcher veered off its flight path, broke up and exploded. 8 / 44

So, what happened? Only one bug: computer program tried to stuff a 64-bit number into a 16-bit space 64 bit floating point number 16 bit integer number This caused that the measured velocities and altitude of Ariane 5 were read wrong. Such measures were followed by extreme control instructions onto the engines, which resulted in self-destruction. 9 / 44

Computer Arithmetic The number x R can be written as: x = (sign)m b c where m is called mantissa, c is exponent and b is basis. For example, the number 117 in decimal system reads 117 = 1.17 102 = (1 100 + 1 10 1 + 7 10 2 ) 102 where (sign) = 1, mantissa m = 1.17, b = 10 and c = 2. However, 117 can be also written in binary system as: 117 = 1.110101 26 where (sign) = 1, m = 1.110101, b = 2 and c = 6. 10 / 44

Computer Arithmetic 117 = 1.110101 26 In this case mantissa is: 1.110101 = 1 20 + 1 2 1 + 1 2 2 + 0 2 3 + 1 2 4 + 0 2 5 + 1 2 6 such that: 117 = (1 26 + 1 25 + 1 24 + 0 23 + 1 22 + 0 21 + 1 20 ) 11 / 44

Computer Arithmetic Every computer has only fixed number of places to store sign, mantissa, basis and exponent. Example: 32 bit number Thus, every computer can represent all numbers x between xmin called underflow level and xmax called overflow level. 12 / 44

IEEE-Standard single-precision floating-point numbers v x = ( 1) (0.1m2 m3...m24 )2 2 c 126, c := (c7...c0 )2 = 7 X ci 2i i=0 double-precision floating-point numbers x = ( 1)v (0.1m2 m3...m53 )2 2c 1021, c := (c10...c0 )2 = 10 X ci 2i i=0 13 / 44

Single-precision numbers x = ( 1)v (0.1m2 m3...m24 )2 2c 126 Special cases: c = 0 (underflow) and c = 255 (overflow) NaN. The smallest and largest representable number: ± amin 1.2 10 38, ± amax ±3.4 1038 The machine precision is eps = 1 23 2 = 2 24 10 7 2 6 up to 7 places precision!! 14 / 44

Double-precision numbers x = ( 1)v (0.1m2 m3...m53 )2 2c 1021 Special cases: c = 0 (underflow) and c = 2047 (overflow). The smallest and largest representable number: ± ± amin 2.2 10 308, amax ±1.8 10308 The machine precision is eps = 1 52 2 10 16 2 15 up to 16 places precision!! 15 / 44

Dangers of computer arithmetic We would like to add two numbers 117000 = 0.1170 106 and 323 = 0.3230 103 on computer which stores mantissa on 4 decimal spaces and exponent on 2. Note: The computer can t add two numbers with different exponents, so it converts the smaller number into a form with the same exponent as the big number. 16 / 44

Dangers of computer arithmetic Thus, 117000 = 0.1170 106 323 = 0.3230 103 = 0.0003 106. After summing, one obtains: 0.1170 106 + 0.0003 106 = 0.1173 106 Finally, result is s = 117300 and correct result is: st = 117323. Conclusion: Buy new computer! 17 / 44

Dangers of computer arithmetic Finally, our computer made: absolute error s = st s = 117323 117300 = 23 relative error s = s 23 = = 1.9604e 04 st 117323 18 / 44

Rounding operation Let some number x R be given as: x = σm10c where the number of digits in mantissa is equal to l. Then, the rounding of x follows from: m = m1 10 1 +... + ml 10 l + r where r = 0 when ml+1 4 and 10 l when ml+1 5. Following this: rd(x) = σ m 10c, rd(x) M 19 / 44

Rounding error Thus, rounding produces error: x = x rd(x) rd(0.551) = 0.55 x = 0.001 rd(0.547) = 0.55 x = 0.003 However, rd(0.551 1020 ) 0.55 1020 x = 1 1017 rd(0.547 1020 ) 0.55 1020 x = 3 1017. 20 / 44

Floating point arithmetic Each arithmetic operation? {+,,, /} is substituted by machine operation {,,, } such that: a b := rd(a? b) = (a? b)(1 + ), a (b c) 6= (a b) cinthesamewayelementaryfunctionsϕ(x) {sin(x), x, exp(x),.. ϕ(x)(1 + ) 21 / 44

II Motivation for today s lecture: Physics: The beam is in equilibrium when F1 = F2 = F. Solving the system: F2 (a + 2b) b (a + b) N1 = F1 (a + 2b) (a + b) b N2 reactions become N1 = N2 = F 22 / 44

II Motivation for today s lecture: Numerics: It can happen that our forces F1 and F2 are not correct (not equal to the real ones) due to rounding, measurement, truncation or approximation errors. Then, one may face the case F1 = F (1 + ε), F2 = F (1 ε) For example: F = 1, F1 = 1.01, F2 = 0.99 ε = 10 2. Then, our system gives a+2b N1 = F (1 + a+2b a ε) and N2 = F (1 a ε). This is different from reality especially 2 when a << b. Think that b = 10, a = 0.1. Then, a+2b = 2.01, and a ε = 201 10 hence N1 = 3.01, N2 = 1.01. 23 / 44

Errors Due to this reason one has to consider sensitivity of our numerics with respect to rounding errors measurement errors errors from earlier computation (programing and truncation errors) 24 / 44

Example By solving the system with an existing error ε 400 + ε 201 200 x= 800 401 200 one obtains different solutions for slight perturbations ε. 100 200 300 Solution x Question is whether we can trust the solution obtained by solving the system with some value of ε we do not know? For example, 400 + ε is obtained from another computation and it is black-box for us (we do not see it, the value is obtained from another subroutine or measurement) 400 500 600 700 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 ε 25 / 44

To answer this question one has... to introduce the notion of sensitivity of the system on perturbations in the data, also known as the condition of the problem. In this respect we may distinguish well-conditioned problem if small perturbations in the data cause small perturbations in the solution ill-conditioned problem if small perturbations in the data cause large perturbations in the solution 26 / 44

Condition number of the function The computer representation of a number is x x We would like to evaluate y = f (x). To achieve this, the computer does the following: y = f (x ). Question: Can we tell how big is: y = y y based on knowledge of x = x x and x? x 27 / 44

Condition number of the function Let us assume that x is small enough such that Taylor expansion y = f (x ) = f (x + x) f = f (x) + x x f = y+ x x holds. Thus, y = = y y f x x 28 / 44

Condition number of the function The relative error of the output is y = f x y = y x y i..e. y = y = k(x) f x x x y x x = k(x) x x The number k(x) = f x x f (x) is called condition number. This number predicts the relative error in output y if the relative error in input x is known. 29 / 44

Condition number of the function In practice this number is often defined as: k(x) = f x x f (x) since y and x are very often given in terms of absolute relative errors, i.e. y = x y and y =. y x Note: in case of the multivariate function (function which depends on the set of arguments x = {x1, x2, }) one may introduce the condition number: kj (x) := f xj (x) xj f (x) 30 / 44

Example x for x = 0.93 is f (x) = 13.28 x 1 x f (x) = for x = 0.94 is f (x) = 15.66 x 1 Slight change in argument x produces jump in function value. This means that the function is ill-conditioned in x = 0.93. On the other hand, f (x) = f (x) = x for x = 0.93 is f (x) = 0.4818 x 1 x for x = 0.94 is f (x) = 0.4845 x 1 Slight change in argument x does not greatly influence the function value. This means that the function is well-conditioned in 0.93. f (x) = 31 / 44

Example The condition number of function f (x) = k(x) x x 1 is = f x x f (x) = 1 x 1 = x (1 x)2 x 1 1 x Thus, k(0.93) = 1 = 14.28 1 0.93 k( 0.93) = 1 = 0.52 1 + 0.93 32 / 44

ill-conditioned part The error in the input x = 0.93 is x = 0.94 0.93 = 0.01 i.e. x = 0.01 x = = 0.0108 1%, x 0.93 hence y = k(0.93) x = 14.28 0.0108 = 0.1535 15% 33 / 44

well-conditioned part The error in the input x = 0.93 is x = 0.94 + 0.93 = 0.01 i.e. x = 0.01 x = = 0.0108 1%, x 0.93 hence y = k( 0.93) x = 0.52 0.0108 = 0.0056 0.5% 34 / 44

Condition number of the system of equations Let us assume the following problem Ax = b x = A 1 b in which the matrix A is non-singular (i.e. it is invertible and has non-zero determinant). If the right hand side is slightly perturbed by b, then one obtains new system of equations Ax = b = b + b x = A 1 (b + b) = A 1 b + A 1 b = x + x Thus, the change in solution is x = A 1 b 35 / 44

Condition number of the system of equations To judge whether the value of x is small or large, let us observe x = A 1 b and use the following inequality k xk ka 1 kk bk in which k k denotes some kind of norm. Then one may conclude the following: If ka 1 k is small, then x will be small only if b is small. If ka 1 k is large, then x can be large even if b is small. 36 / 44

Condition number of the system of equations Following this, let us evaluate k xk ka 1 kk bk kakka 1 kk bk =. kxk kxk kakkxk From original system Ax = b we have kakkxk kbk which leads i.e. kakka 1 kk bk kakka 1 kk bk k xk kxk kakkxk kbk k xk k bk k bk kakka 1 k = k(a) kxk kbk kbk 37 / 44

Condition number of the system of equations The condition number k(a) in k xk k bk k(a) kxk kbk finally gives us the rule of checking if our system is well-conditioned or not: if k(a) is small, then the system is well-conditioned otherwise, if k(a) is large then the system is ill-conditioned 38 / 44

Condition number of the system of equations Similar conclusion can be made if one adds perturbations A to the matrix itself: (A + A )x = b = b + b (A + A )(x + x) = b = b + b x = A 1 ( b A x A x) This leads to inequality k xk = ka 1 k(k bk + k A kkxk + k A kk xk) i.e. (1 ka 1 kk A k)k xk ka 1 k(k bk + k A kkxk) Dividing both sides by kxk one obtains k xk ka 1 k kxk 1 ka 1 kk A k k bk + k A k kxk 39 / 44

Condition number of the system of equations The inequality k xk ka 1 k kxk 1 ka 1 kk A k k bk + k A k kxk further can be modified as k xk kakka 1 k Ak kxk 1 kakka 1 k k kak which leads to k xk k(a) Ak kxk 1 k(a) k kak k bk k A k + kakkxk kak k bk k A k + kbk kak 40 / 44

Condition number of the system of equations Assuming that the perturbation A is small enough such that ka 1 kk A k << 1 holds, one may simplify k xk k(a) Ak kxk 1 k(a) k kak to k xk k(a) kxk k bk k A k + kbk kak k bk k A k + kbk kak Hence, again the same conclusion if k(a) is small, then the system is well-conditioned otherwise, if k(a) is large then the system is ill-conditioned 41 / 44

Example The system 400 800 201 200 x= 401 200 is ill-conditioned because k(a) = kakka 1 k = 1.0006 103 2.5015 = 2.5030 103 Hence, the system is sensitive to both perturbations in the right hand side and matrix itself. 42 / 44

Literature http://people.ds.cam.ac.uk/nmm1/arithmetic/na1.pdf http://homerreid.dyndns.org/teaching/18.330/notes/ MachineArithmetic.pdf Roland Angst. The Condition of a System of Linear Equations: Alternative Derivation http://www.cs.cornell.edu/~bindel/class/cs4220-s15/lec/ 2015-02-04-notes.pdf http://nucinkis-lab.cc.ic.ac.uk/helm/workbooks/workbook_30/ 30_4_matrx_norms.pdf 43 / 44

Any questions? 44 / 44