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

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

Math 471. Numerical methods Introduction

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

Chapter 1: Introduction and mathematical preliminaries

Notes for Chapter 1 of. Scientific Computing with Case Studies

Chapter 1 Mathematical Preliminaries and Error Analysis

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

ECS 231 Computer Arithmetic 1 / 27

Lecture Notes 7, Math/Comp 128, Math 250

Numerical Analysis and Computing

Mathematical preliminaries and error analysis

Jim Lambers MAT 610 Summer Session Lecture 2 Notes

1 Floating point arithmetic

Introduction to Finite Di erence Methods

Lecture 7. Floating point arithmetic and stability

Binary floating point

2. Review of Calculus Notation. C(X) all functions continuous on the set X. C[a, b] all functions continuous on the interval [a, b].

Elements of Floating-point Arithmetic

How do computers represent numbers?

Elements of Floating-point Arithmetic

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

Midterm Review. Igor Yanovsky (Math 151A TA)

1 ERROR ANALYSIS IN COMPUTATION

Notes on floating point number, numerical computations and pitfalls

Round-off Errors and Computer Arithmetic - (1.2)

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

Numerical Algorithms. IE 496 Lecture 20

Chapter 1 Computer Arithmetic

MTH303. Section 1.3: Error Analysis. R.Touma

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

Chapter 1 Error Analysis

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

ACM 106a: Lecture 1 Agenda

Errors. Intensive Computation. Annalisa Massini 2017/2018

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

MAT 460: Numerical Analysis I. James V. Lambers

FLOATING POINT ARITHMETHIC - ERROR ANALYSIS

Introduction and mathematical preliminaries

Floating-point Computation

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

Introduction CSE 541

INTRODUCTION TO COMPUTATIONAL MATHEMATICS

ESO 208A: Computational Methods in Engineering. Saumyen Guha

STEP Support Programme. Hints and Partial Solutions for Assignment 17

Introduction to Numerical Analysis

Chapter 4 Number Representations

P.1 Prerequisite skills Basic Algebra Skills

Lesson 21 Not So Dramatic Quadratics

FLOATING POINT ARITHMETHIC - ERROR ANALYSIS

Mathematics Review. Sid Rudolph

Chapter 1A -- Real Numbers. iff. Math Symbols: Sets of Numbers

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

MATH ASSIGNMENT 03 SOLUTIONS

Remainders. We learned how to multiply and divide in elementary

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

Algebra One Dictionary

1 Backward and Forward Error

ALGEBRA GRADE 7 MINNESOTA ACADEMIC STANDARDS CORRELATED TO MOVING WITH MATH. Part B Student Book Skill Builders (SB)

CS412: Introduction to Numerical Methods

Chapter 1: Preliminaries and Error Analysis

Quadratic Equations Part I

Undergraduate Notes in Mathematics. Arkansas Tech University Department of Mathematics. College Algebra for STEM

Math 096--Quadratic Formula page 1

Numerical Methods - Preliminaries

Lecture 28 The Main Sources of Error


Solutions to Assignment 1

Introduction to Scientific Computing

Leaving Cert Differentiation

Queens College, CUNY, Department of Computer Science Numerical Methods CSCI 361 / 761 Spring 2018 Instructor: Dr. Sateesh Mane.

Numerical Methods - Lecture 2. Numerical Methods. Lecture 2. Analysis of errors in numerical methods

Homework and Computer Problems for Math*2130 (W17).

Math 115 Syllabus (Spring 2017 Edition) By: Elementary Courses Committee Textbook: Intermediate Algebra by Aufmann & Lockwood, 9th Edition

CH 59 SQUARE ROOTS. Every positive number has two square roots. Ch 59 Square Roots. Introduction

Examples MAT-INF1100. Øyvind Ryan

CHAPTER EIGHT: SOLVING QUADRATIC EQUATIONS Review April 9 Test April 17 The most important equations at this level of mathematics are quadratic

College Algebra. Chapter 5 Review Created by: Lauren Atkinson. Math Coordinator, Mary Stangler Center for Academic Success

Homework 2. Matthew Jin. April 10, 2014

HOSTOS COMMUNITY COLLEGE DEPARTMENT OF MATHEMATICS INTENSIVE INTEGRATED ARITHMETIC/ALGEBRA. Placement score of 25 or above on the COMPASS M1

1.1 COMPUTER REPRESENTATION OF NUM- BERS, REPRESENTATION ERRORS

Reading Mathematical Expressions & Arithmetic Operations Expression Reads Note

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

Math Precalculus I University of Hawai i at Mānoa Spring

MATH Dr. Halimah Alshehri Dr. Halimah Alshehri

Math 128A: Homework 2 Solutions

Beginning Algebra. 1. Review of Pre-Algebra 1.1 Review of Integers 1.2 Review of Fractions

Algebra Summer Review Packet

Math 1302 Notes 2. How many solutions? What type of solution in the real number system? What kind of equation is it?

Outline. Math Numerical Analysis. Intermediate Value Theorem. Lecture Notes Zeros and Roots. Joseph M. Mahaffy,

Math ~ Exam #1 Review Guide* *This is only a guide, for your benefit, and it in no way replaces class notes, homework, or studying

Parent Guide. Number System. Diocese of Cleveland

Math Numerical Analysis

Unit 2-1: Factoring and Solving Quadratics. 0. I can add, subtract and multiply polynomial expressions

Essential Mathematics

Numerical Methods in Physics and Astrophysics

Caculus 221. Possible questions for Exam II. March 19, 2002

1 Solving Algebraic Equations

Final Exam A Name. 20 i C) Solve the equation by factoring. 4) x2 = x + 30 A) {-5, 6} B) {5, 6} C) {1, 30} D) {-5, -6} -9 ± i 3 14

Algebra I. AIR Study Guide

Chapter 1 Mathematical Preliminaries and Error Analysis

Transcription:

Tu: 9/3/13 Math 71, Fall 2013, Section 001 Lecture 1 1 Course intro Notes : Take attendance. Instructor introduction. Handout : Course description. Note the exam days (and don t be absent). Bookmark the course webpage. Matlab: We ll use it but I won t have time to teach coding note the o ce hours. Tests : non-programmable calculators only, plus one-page of notes (one-sided for midterm, two-sided for final). Assigned reading : Bradie, chapter 1. Not all topics from the text will be covered in class, some homework problems / test problems may come from material in the text or course webpage, even if they aren t explicitly covered in class. Numerical methods How to solve equations with computers Building blocks of all computer models How to use them we cannot always trust a computed result Black box syndrome: Modelers beware! The following graphic depicts 9 di erent models solutions to the linear advection equation in spherical geometry. The models are all either operational climate models.

2 Representing numbers Question 1: What representations are exact? Which are approximate? 2.1 Symbolic representation Example 1: e 2 3 p 2

2.2 Numerical representation We use a positional system. The position of each digit relative to the point guides our understanding of the number. x = ± (d n d n 1 d n 2 d 1 d 0.d 1 d 2 ) = ± d n n + d n 1 n 1 + + d 0 0 + d 1 1 + d 2 2 + = base, d i = digits, 0 apple d i apple 1 for all i Other common bases are = 8 and = 16; perhaps = 60? Example 2: = 10 : decimal (2013) 10 =2 10 3 +0 10 2 +1 10 1 +3 10 0 (0.360) 10 =3 10 1 +6 10 2 +0 10 3 Example 3: = 2 : binary (101011.01) 2 =1 2 5 +0 2 +1 2 3 +0 2 2 +1 2 1 +1 2 0 +0 2 1 +1 2 2 = 32 + 8 + 2 + 1 + 0.25 = (3.25) 10 = 10 1 +3 10 0 +2 10 1 +5 10 2 Question 2: Are the above numerical representations exact? Question 3: Why do humans prefer the decimal representation? Why would binary make sense for computers? 2.3 Floating point representation Computers use a floating point representation for real numbers. Constant number of significant digits. Text: section 1.3 Unlike the previous two sections, floating point representations presume a finite number of digits, and hence necessarily approximate irrational numbers and even some rationals. Question : Is a floating point representation exact?

Question 5: human? Why would this be necessary in a typical computer, but not necessarily so for a A floating point number is represented as x =(0.d 1 d 2 d n ) e d 1 6= 0 (1) where n is the number of significant digits, is the base, and e is the exponent. The string of digits, d 1 d 2 d n is called the mantissa. A floating point number system is defined by n, and M, wherem is an integer such that M apple e apple M. In IEEE double precision (the standard for most scientific computing), = 2, n = 53, and M = 1023. Numbers are stored across 6 bits (bit = binary digit). 1 bit = sign of mantissa, 1 bit = sign of exponent, the mantissa is stored across 52 bits, which leaves 10 bits for the exponent. Notes Floating point number systems are discrete (finite and not continuous) sets They have a maximum element and a minimum element They contain the number zero, and have a smallest positive element and a largest negative element Question 6: What does multiplication by e do in (1)? Example : Consider the floating point system defined by = 2, n =, and M = 3. 1. What is the largest element in this set? The largest element in any floating point system will have every d i = possible exponent. Thus, 1, and the largest x max =(0.1111) 2 2 3 =(2 1 +2 2 +2 3 +2 ) 2 3 =2 2 +2+1+0.5 =(7.5) 10 2. What is the smallest positive element of this set? The smallest positive number in the system will have only 1 nonzero significant digit, and the minimum exponent: x min =(0.1000) 2 2 3 =2 =(0.0625) 10

Definition 1. Absolute error, E A. Let p 2 R be a real number and let p be an approximation of p. E A = p p Definition 2. Relative error, E R. Let p 2 R be a real number and let p be an approximation of p. E R = p p p Let fl(x) be the floating point representation associate with x 2 R. Then x fl(x) is roundo error. Example 5: = 3.1159265358797 = (11.00100100001 ) 2 1. For the system discussed earlier, with = 2,n =,M = 3, the representation of is rounded to fl( ) =(0.1101) 2 2 2 =(3.25) 10. This is the closest floating point number to in that system. 2. In reality, with n = 52, the roundo error in fl( ) is approximately 2 52 10 15. The numbers that define a floating point system are determined by the hardware and software you use (loosely, your machine ). Definition 3. Machine precision. The largest relative gap between floating point numbers is defined as a machine unit, u, and is given by u = 1 2 1 n. See page 36 for the derivation of this quantity. 2.3.1 Floating point arithmetic Text: section 1. Assumption. For all x 2 R, there is an with <usuch that fl(x) =x(1 + ). Thus, the di erence between any real number and its floating point representation is always less than machine precision, in relative terms, i.e., x fl(x) <xu.

Definition 5. Big O notation. To say that f(h) = O(g(h)) implies proportionality and a limit. If f(h) and g(h) are two functions of h, then f(h) =O g(h) as h! 0 implies that there exists a constant C such that f(h) < C g(h) for all h su ciently small. The interpretation is that f(h) decays to zero at least as fast as g(h) as h! 0. Question 7: How do roundo errors behave under basic arithmetic operations (addition, subtraction, multiplication, division)? 1. Is fl(x) fl(y) =xy(1 + ) for some <u? fl(x) fl(y) =x(1 + x )y(1 + y ) = xy(1 + x + y + x y ) We define xy = x + y and note that since both x and y are very small, x y is much smaller. Thus, fl(x) fl(y) =xy(1 + xy )+O( 2 ) as! 0. 2. Is fl(x)+fl(y) =(x + y)(1 + ) for some <u? Beware! fl(x)+fl(y) =x(1 + x )+y(1 + y ) = x + x x + y + y y =(x + y) 1+ x x + y y x + y Although we may assume that x and y are small, x x and y y might not be. Further more, if x + y 0, the denominator becomes unbounded, and fl(x) +fl(y) may not be close to x + y at all! Example 6: Consider a decimal digit floating point system with x =0.123 and y = 0.1233. Then x + y =0.0001 = (0.1000) 10 10 3. This result has only 1 significant digit. This is known as cancellation error. Example 7: Quadratic formula, page 5. ax 2 + bx + c =0 ) x = b ± p b 2 ac 2a 0.2x 2 7.91x +6=0 ) x = 239.27, 0.1253 : Matlab

Now suppose we use decimal digit arithmetic. x = 7.91 ± p 7.91 2 (0.2)6 2(0.2) 8 = 7.91 ± 7.85 0. >< = >: 7.91 + 7.85 0. 7.91 7.85 0. = 7.91 ± p 2295.8 0. = 95.76 0. = 0.06 0. = 7.91 ± p 2290 0. = 239. : all digits are correct =0.15 : only 1 digit is correct The problem is due to loss of significance in the subtraction 7.91 7.85. One remedy is to use higher precision arithmetic (Matlab), but another option is to reformulate the arithmetic. x = b p b 2 ac 2a = b + p b 2 ac b + p b 2 ac = b2 (b 2 ac) 2a( b + p b 2 ac) = 2c b + p b 2 2 6 7.91 + 7.85 = 12 95.76 =0.1253 : now all digits are correct ac 3 Finite di erences Text: section 6.2 Recall : We have discussed roundo error due to floating point representations and floating point arithmetic each of these will appear when we use a computer to evaluate a function. Question 8: Idea : How do we evaluate derivatives of functions? Start with the definition of a derivative... then approximate for some step size h>0 f 0 f(x + h) f(x) (x) =lim, h!0 h f 0 f(x + h) (x) f(x) h = D + f(x). (2) Graphically, we are approximating the slope of the tangent line to f(x) with the slope of the secant line between f(x) and f(x + h). x x + h

Question 9: How accurate should we expect (2) to be? Taylor series analysis : Recall: f(x) =f(a)+f 0 (a)(x a)+ 1 2 f 00 (a)(x a) 2 + 1 6 f 000 (a)(x a) 3 + (3) We write (3) in an equivalent form. Replace x with x + h and replace a with x. Thenx in (3) and a = h f(x + h) =f(x)+f 0 (x)h + 1 2 f 00 (x)h 2 + 1 6 f 000 (x)h 3 + =) f 0 f(x + h) f(x) (x) = {z } {z h } exact value approximation h 2 f 00 1 (x) 6 h2 f 000 (x) {z } truncation error Thus, the error in our approximation (2) is proportional to h, since f 0 (x) f(x + h) h f(x) = h 2 f 00 (x)+o(h 2 ), and we say that D + f(x) is a first order approximation of f 0 (x), since D + f(x) =f 0 (x)+o(h). Thursday, 9/5/13 Example 8: If f(x) =e x,x= 1, then f 0 (1) = e =2.71828... is the exact value. h D + f f 0 (x) D + f (f 0 (x) D + f)/h 0.1 2.8588-0.106-1.056 0.05 2.787-0.0691-1.3821 0.025 2.7525-0.033-1.3705 0.0125 2.7353-0.0171-1.368 # # # # e 0 e 0 2 = 1 2 f 00 (1) Beware! In practice something unexpected happens when h is very small. 1 clear ; 2 %% F o r w a r d d i f f e r e n c e d e m o n s t r a t i o n 3 exact value = exp (1); 5 tic 6 7 for j=1:65 8 h( j ) = 1/2ˆj ; 9 computed value = (exp(1+h( j )) exp (1))/h(j ); 10 error(j) = abs(exact value computed value ); 11 end 12

13 figure (1); clf ; 1 plot(h,error,h,error, o, LineWidth,2, MarkerSize,12); 15 set( gca, FontSize,18); 16 xlabel( step size, h ); 17 ylabel( error ); 18 title( Forward Difference error vs. step size ); 19 20 figure (2); clf ; 21 loglog(h,error,h,error, o, LineWidth,2, MarkerSize,12); 22 set( gca, FontSize,18); 23 xlabel( step size, h ); 2 ylabel( error ); 25 title( Forward Difference error vs. step size ); 26 27 toc 28 29 saveas ( 1, f w d D i f f linearplot.png ); 30 saveas ( 2, f w d D i f f logplot.png );

Note : If error Ch p, then log(error) = log C + p log h, i.e. the slope of the data on a log-log plot gives the order of convergence. Question 10: Why does error increase for very small h (the left side of the plot)? D + f(x) has two sources of error: truncation error due to not using the entire Taylor series, and roundo error due to finite precision arithmetic. Truncation error, we have shown, is O(h), and roundo error is O( /h), where 10 15 in Matlab. The total error is therefore O(h)+O( /h), hence for large h (relative to ) truncation error dominates the computation, but for small h, roundo error is dominant. Note : Other finite di erence approximations of first derivatives are possible, for example, Backward di erence: D f(x) = Centered di erence: D 0 f(x) = f(x) f(x h). h f(x + h) f(x h) 2h (homework).

Matlab Intro basic data type = complex matrix, double precision Loops preallocation the colon operator elemental vs. array operations transpose clear, mod, if, elseif, end