COS 323: Computing for the Physical and Social Sciences

Similar documents
COS 323: Computing for the Physical and Social Sciences

Mathematical preliminaries and error analysis

2.1.1 Fixed-Point (or Integer) Arithmetic

Math 340 Fall 2014, Victor Matveev. Binary system, round-off errors, loss of significance, and double precision accuracy.

Scientific Computing. Error Analysis

CS321. Introduction to Numerical Methods

CS321 Introduction To Numerical Methods

Computational Methods. Sources of Errors

MAT128A: Numerical Analysis Lecture Two: Finite Precision Arithmetic

Computing Basics. 1 Sources of Error LECTURE NOTES ECO 613/614 FALL 2007 KAREN A. KOPECKY

2 Computation with Floating-Point Numbers

Introduction to Scientific Computing Lecture 1

Accuracy versus precision

Truncation Errors. Applied Numerical Methods with MATLAB for Engineers and Scientists, 2nd ed., Steven C. Chapra, McGraw Hill, 2008, Ch. 4.

Scientific Computing: An Introductory Survey

2 Computation with Floating-Point Numbers

What Every Programmer Should Know About Floating-Point Arithmetic

Chapter 3. Errors and numerical stability

AM205: lecture 2. 1 These have been shifted to MD 323 for the rest of the semester.

Floating-point representation

Floating Point Arithmetic

1.3 Floating Point Form

Numerical computing. How computers store real numbers and the problems that result

Lecture Objectives. Structured Programming & an Introduction to Error. Review the basic good habits of programming

CHAPTER 2 SENSITIVITY OF LINEAR SYSTEMS; EFFECTS OF ROUNDOFF ERRORS

What we need to know about error: Class Outline. Computational Methods CMSC/AMSC/MAPL 460. Errors in data and computation

Computational Methods CMSC/AMSC/MAPL 460. Representing numbers in floating point and associated issues. Ramani Duraiswami, Dept. of Computer Science

CS 542G: Preliminaries, Floating-Point, Errors

1.2 Round-off Errors and Computer Arithmetic

fractional quantities are typically represented in computers using floating point format this approach is very much similar to scientific notation

Basics of Computation. PHY 604:Computational Methods in Physics and Astrophysics II

MATH 353 Engineering mathematics III

Numerical Methods 5633

Review Questions 26 CHAPTER 1. SCIENTIFIC COMPUTING

Rev Name Date. . Round-off error is the answer to the question How wrong is the rounded answer?

Numerical Precision. Or, why my numbers aren t numbering right. 1 of 15

Numerical Computing: An Introduction

MA 1128: Lecture 02 1/22/2018

unused unused unused unused unused unused

Introduction to Computers and Programming. Numeric Values

New Mexico Tech Hyd 510

ME 261: Numerical Analysis. ME 261: Numerical Analysis

Chapter 03: Computer Arithmetic. Lesson 09: Arithmetic using floating point numbers

Unavoidable Errors in Computing

Floating-Point Numbers in Digital Computers

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Scientific Computing: An Introductory Survey

Floating-Point Numbers in Digital Computers

(Refer Slide Time: 02:59)

Computational Mathematics: Models, Methods and Analysis. Zhilin Li

CS 261 Fall Floating-Point Numbers. Mike Lam, Professor.

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Number Systems and Number Representation

Floating Point Arithmetic

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

CS 261 Fall Floating-Point Numbers. Mike Lam, Professor.

Computational Economics and Finance

Floating Point. CSC207 Fall 2017

Limits. f(x) and lim. g(x) g(x)

Exponential Numbers ID1050 Quantitative & Qualitative Reasoning

Objectives. look at floating point representation in its basic form expose errors of a different form: rounding error highlight IEEE-754 standard

Chapter Three. Arithmetic

Floating-Point Arithmetic

Binary floating point encodings

Foundations of Computer Systems

Computational Economics and Finance

Princeton University Computer Science 217: Introduction to Programming Systems. Goals of this Lecture. Number Systems and Number Representation

Hani Mehrpouyan, California State University, Bakersfield. Signals and Systems

Lecture Notes to Accompany. Scientific Computing An Introductory Survey. What is scientific computing?

Floating-Point Arithmetic

Floating-point numbers. Phys 420/580 Lecture 6

LABORATORY. 3 Representing Numbers OBJECTIVE REFERENCES. Learn how negative numbers and real numbers are encoded inside computers.

Classes of Real Numbers 1/2. The Real Line

Number Systems and Computer Arithmetic

Rollover. from xkcd.com

3.1 DATA REPRESENTATION (PART C)

IEEE Floating Point Numbers Overview

3.5 Floating Point: Overview

Number Representations

Decimal Binary Conversion Decimal Binary Place Value = 13 (Base 10) becomes = 1101 (Base 2).

Most nonzero floating-point numbers are normalized. This means they can be expressed as. x = ±(1 + f) 2 e. 0 f < 1

Floating Point Representation. CS Summer 2008 Jonathan Kaldor

Up next. Midterm. Today s lecture. To follow

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: Bits and Bytes and Numbers

Algebra 2 Semester 2 Final Exam Study Outline Semester 2 Final Exam Study Tips and Information

MAT 003 Brian Killough s Instructor Notes Saint Leo University

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Introduction to floating point arithmetic

Section 1.4 Mathematics on the Computer: Floating Point Arithmetic

HW DUE Floating point

More Programming Constructs -- Introduction

LECTURE 0: Introduction and Background

8/30/2016. In Binary, We Have A Binary Point. ECE 120: Introduction to Computing. Fixed-Point Representations Support Fractions

6.1 Evaluate Roots and Rational Exponents

Outline. 1 Scientific Computing. 2 Approximations. 3 Computer Arithmetic. Scientific Computing Approximations Computer Arithmetic

FLOATING POINT NUMBERS

YEAH 2: Simple Java! Avery Wang Jared Bitz 7/6/2018

Module 2: Computer Arithmetic

ACCELERATED MATH 6/7 Plans QUARTER

Finite arithmetic and error analysis

Transcription:

COS 323: Computing for the Physical and Social Sciences

COS 323 Professor: Szymon Rusinkiewicz TAs: Mark Browning Fisher Yu Victoria Yao Course webpage http://www.cs.princeton.edu/~cos323/

What s This Course About? Numerical Algorithms Analysis of Data Simulation Learn through applications

Scientific Computing Computers, from their invention until the 70s/80s, were used mostly to solve problems Before personal computers (!) Users were scientists: producers of numerical codes rather than consumers of applications

Betty Jean Jennings and Fran Bilas with ENIAC I first general-purpose electronic computer

Stanisław Ulam with MANIAC I about 10 4 ops/sec

8 out of the top 10 algorithms of the 20 th century are numerical in nature (we ll cover 6 of them)

Some challenging but important & common problems

Root finding E.g., estimate molal volume of a gas at a given pressure & temperature using van der Waals: (p + a/v 2 )(v-b) = RT

Solving systems of linear equations e.g., determine the current at each point in an electrical circuit, using Kirchoff s rule and Ohm s law.

Optimization E.g., design the cheapest wastewater treatment given geography, pollution patterns, and environmental regulations.

Integration E.g., compute the work performed in a mechanical system given a variable force

How do we solve these problems?

Numerical Analysis Algorithms for solving numerical problems Calculus, algebra, data analysis, etc. Used even if answer is not simple/elegant: math in the real world Analyze/design algorithms based on: Running time, memory usage (both asymptotic and constant factors) Applicability, stability, and accuracy

Why Is This Hard/Interesting? Numbers in computers numbers in math Limited precision and range Algorithms sometimes don t give right answer Iterative, randomized, approximate Unstable Tradeoffs in accuracy, stability, and running time

Numbers in Computers and their consequences

Numbers in Computers Integers Implemented in hardware: fast Mostly sane, except for limited range Floating point Implemented in most hardware Much larger range (e.g. 2 31... 2 31 for integers, vs. 2 127... 2 127 for FP) Lower precision (e.g. 7 digits vs. 9) Relative precision: actual accuracy depends on size

Floating Point Numbers Like scientific notation: e.g., c is 2.99792458 10 8 m/s This has the form (multiplier) (base) (power) In the computer, Multiplier is called mantissa Base is almost always 2 Power is called exponent

Modern Floating Point Formats Almost all computers use IEEE 754 standard Single precision : 24-bit mantissa, base = 2, 8-bit exponent, 1 bit sign All fits into 32 bits (!) mantissa has implicit leading 1 Double precision : 53-bit mantissa, base = 2, 11-bit exponent, 1 bit sign All fits into 64 bits Sometimes also have extended formats

Other Number Representations Fixed point Absolute accuracy doesn t vary with magnitude Represent fractions to a fixed precision Not supported directly in hardware, but can hack it Infinite precision Integers or rationals allocated dynamically Can grow up to available memory No direct support in hardware, but libraries available

Consequences of Floating Point Machine epsilon : smallest positive number you can add to 1.0 and get something other than 1.0 For single precision: ε 10 7 No such number as 1.000000001 Rule of thumb: almost 7 digits of precision For double: ε 2 10 16 Rule of thumb: not quite 16 digits of precision These are all relative numbers

So What? Simple example: add 1 / 10 to itself 10 times

Yikes! Result: 1 / 10 + 1 / 10 + 1 Reason: 0.1 can t be represented exactly in binary floating point Like 1 / 3 in decimal Rule of thumb: comparing floating point numbers for equality is always wrong

More Subtle Problem Using quadratic formula x = b ± b2 4aa 2a to solve x 2 9999x + 1 = 0 Only 4 digits: single precision should be OK, right? Correct answers: 0.0001 and 9998.999 Actual answers in single precision: 0 and 9999 First answer is 100% off! Total cancellation in numerator because b 2 >> 4ac

Accuracy error is inevitable

Catalog of Errors Roundoff error caused by limitations of floating-point numbers Truncation error caused by stopping an approximate technique early e.g., too few terms of Taylor series for sin(θ ) Inherent error limitation on data available Garbage in, garbage out Statistical error too few random samples

Error Tradeoff [Heath]

Other Considerations of Problem Formulation & Algorithm Sensitivity & conditioning, stability & accuracy

Well-Posedness and Sensitivity Problem is well-posed if solution exists is unique depends continuously on problem data Otherwise, problem is ill-posed Solution may still be sensitive to input data Ill-conditioned: relative change in solution much larger than that in input data [Heath]

Sensitivity & Conditioning Some problems propagate error in bad ways e.g., y = tan(x) sensitive to small changes in x near π/2 Small error in input huge error in solution: ill-conditioned Well-conditioned problems may have ill-conditioned inverses, and vice versa e.g., y = atan(x)

Stability & Accuracy A stable algorithm introduces only a little computational error Solution is an exact to solution to a nearby problem Computational error is indistinguishable from small data error An accurate algorithm produces a solution that is close to the true solution stable algorithm + well-conditioned problem accurate solution.

Running time

Running Time Depending on algorithm, we ll look at: Asymptotic analysis for noniterative algorithms (e.g., most methods for inverting an n n matrix require time proportional to n 3 ) Convergence order for iterative approximate algorithms (e.g., an answer to precision δ might require iterations proportional to 1/δ or 1/δ 2 )

Course Overview

Basic Techniques root finding optimization linear systems integration ODEs, PDEs Plus

Signal Analysis & Signal Processing [Matusik & McMillan]

Data Analysis and Model Fitting

Visualization

Simulation

Simulation

Simulation

Simulation In summary, a zombie outbreak is likely to lead to the collapse of civilisation, unless it is dealt with quickly. While aggressive quarantine may contain the epidemic, or a cure may lead to coexistence of humans and zombies, the most effective way to contain the rise of the undead is to hit hard and hit often. As seen in the movies, it is imperative that zombies are dealt with quickly, or else we are all in a great deal of trouble. Munz et al. 2009

Course Information

Mechanics 5 programming assignments: 50% Typically more thought than coding Some in MATLAB, some in Java Analysis, writeup counts a lot! 2 in-class exams: 25% Short-answer, focusing on topics not covered in programming assignments Final project (in groups): 25%

Assignment 0 Will be available on course web page by tomorrow, due Tuesday Sep 25 Before then: Review syllabus and schedule at http://www.cs.princeton.edu/~cos323/ Install Matlab Sign up for Piazza at http://piazza.com/class#fall2011/cos323