09_scientific - 1 Introduction to Computer Science •...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 Introduction to Computer Science • Sedgewick and Wayne • Copyright © 2007 • http://www.cs.Princeton.EDU/IntroCS 9. Scientific Computing 2 Applications of Scientific Computing Science and engineering challenges.  Fluid dynamics.  Seismic surveys.  Plasma dynamics.  Ocean circulation.  Electronics design.  Pharmaceutical design.  Human genome project.  Vehicle crash simulation.  Global climate simulation.  Nuclear weapons simulation.  Molecular dynamics simulation. Common features.  Problems tend to be continuous instead of discrete.  Algorithms must scale to handle huge problems. Commercial applications.  Web search.  Financial modeling.  Computer graphics.  Digital audio and video.  Natural language processing.  Architecture walk-throughs.  Medical diagnostics (MRI, CAT). 3 Floating Point IEEE 754 representation.  Used by all modern computers.  Scientific notation, but in binary.  Single precision: float = 32 bits.  Double precision: double = 64 bits. Ex. Single precision representation of -0.453125 . 1 0 1 1 1 1 1 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 sign bit exponent significand 125 1/2 + 1/4 + 1/16 = 0.8125-1 -1 × 2 125- 127 × 1. 8125 = -0.453125 bias phantom bit 4 Floating Point Remark. Most real numbers are not representable, including π and 1/10. Roundoff error. When result of calculation is not representable. Consequence. Non-intuitive behavior for uninitiated. Financial computing. Calculate 9% sales tax on a 50¢ phone call. Banker's rounding. Round to nearest integer, to even integer if tie. if ( 0.1 + 0.2 == 0.3 ) { // NO } if ( 0.1 + 0.3 == 0.4 ) { // YES } double a1 = 1.14 * 75 ; // 85.49999999999999 double a2 = Math . round ( a1 ); // 85 double b1 = 1.09 * 50 ; // 54.50000000000001 double b2 = Math . round ( b1 ); // 55 SEC violation (!) you lost 1¢ 2 5 Floating Point Floating point numbers are like piles of sand; every time you move them around, you lose a little sand and pick up a little dirt. - Kernighan and Plauger 6 Catastrophic Cancellation A simple function. Goal. Plot f(x) for -4 ⋅ 10-8 ≤ x ≤ 4 ⋅ 10-8 . Exact answer f ( x ) = 1 − cos x x 2 7 Catastrophic Cancellation A simple function. Goal. Plot f(x) for -4 ⋅ 10-8 ≤ x ≤ 4 ⋅ 10-8 . f ( x ) = 1 − cos x x 2 IEEE 754 double precision answer 8 Catastrophic Cancellation Ex. Evaluate fl(x) for x = 1.1e-8 .  Math.cos(x) = 0.99999999999999988897769753748434595763683319091796875 .  (1.0 - Math.cos(x)) = 1.1102e-16  (1.0 - Math.cos(x)) / (x*x) = 0.9175 Catastrophic cancellation. Devastating loss of precision when small numbers are computed from large numbers, which themselves are subject to roundoff error....
View Full Document

This note was uploaded on 09/21/2009 for the course COMPUTER computer 1 taught by Professor Abedauthman during the Fall '08 term at Aarhus Universitet.

Page1 / 13

09_scientific - 1 Introduction to Computer Science •...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online