Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Scientific Computation

Similar presentations


Presentation on theme: "Introduction to Scientific Computation"— Presentation transcript:

1 Introduction to Scientific Computation
Whom do you call…?

2 Copyright, G. A. Tagliarini, PhD
Common Problems Intractable analytical representations Model building: sample data are available but no closed form analytical representation for a relation Need to estimate intermediate behavior (interpolation) Need to predict/forecast behavior (extrapolation) Change representation from one domain to another (e.g., DSP) 11/21/2018 Copyright, G. A. Tagliarini, PhD

3 Copyright, G. A. Tagliarini, PhD
Computing Issues Inherently discrete representation Finite ranges that vary according to the space allocated to store the representation Alternative arithmetic systems Integers (two’s complement representation) Floating point (IEEE 754) 11/21/2018 Copyright, G. A. Tagliarini, PhD

4 Computer Integer Arithmetic
Representations assume n bits bn-1…b0 Unsigned Range is [0, 2n-1], there is no sign so all bits can be used to represent magnitude Example with n=8 and x = = Typically used to represent storage addresses Signed magnitude Two’s complement 11/21/2018 Copyright, G. A. Tagliarini, PhD

5 Computer Integer Arithmetic
Representations assume n bits bn-1…b0 Unsigned Signed magnitude Range is [-(2n-1-1), 2n-1-1] including two zeros! In the representation bn-1…b0, bn-1 represents the sign and bn-2…b0 the magnitude Example with n=8 and x = = Typically not used Two’s complement 11/21/2018 Copyright, G. A. Tagliarini, PhD

6 Computer Integer Arithmetic
Representations assume n bits bn-1…b0 Unsigned Signed magnitude Two’s complement Asymmetric range is [-2n-1, 2n-1-1] includes only one zero! In the representation bn-1…b0, bn-1 indicates the sign but is also used to determine the magnitude Example with n=8 and x = = 2810 11/21/2018 Copyright, G. A. Tagliarini, PhD

7 Two’s Complement Representation of a Negative Quantity
Assume x<0 Find y = |x| Determine the unsigned binary representation of y = bn-1…b0 Complement each bit (replace each 0 with 1 and each 1 with 0) to form y’ = bn-1’…b0’, where bi’=(1-bi), for i e {0, 1,…, n-1} Add 1 to complete the representation 11/21/2018 Copyright, G. A. Tagliarini, PhD

8 Two’s Complement Representation of a Negative Quantity
Assume n = 8 and x = -28 (note x<0) Find y = |x| → y = 2810 Determine the unsigned binary representation of y = bn-1…b0 → y = Complement each bit to form y’ = Add 1 to form the two’s complement representation of -28 which is y’+1 = Note: = 0, as expected! (Remember that the field width is fixed.) 11/21/2018 Copyright, G. A. Tagliarini, PhD

9 Two’s Complement Interpretation
If bn-1 = 0, interpret as the corresponding unsigned (non-negative) integer If bn-1 = 1, Complement each bit Add 1 Interpret the result as an unsigned quantity Attach the “-” sign 11/21/2018 Copyright, G. A. Tagliarini, PhD

10 Two’s Complement Interpretation
Example where bn-1 = 1, x = Complement each bit → Add 1 → Interpret the result as an unsigned quantity → 10010 Attach the “-” sign → 11/21/2018 Copyright, G. A. Tagliarini, PhD

11 Review of Single Precision IEEE 754 Floating Point Notation
Uses 32-bits in three fields: Sign (a 1-bit field) 0 - nonnegative 1 - negative Biased exponent (an 8-bit field) Bias equals (or ) Normalized mantissa (a 23-bit field) Leading “1” omitted 11/21/2018 Copyright, G. A. Tagliarini, PhD

12 Conversion to IEE 754 Representation
Select the appropriate value for the sign bit Write the quantity in normalized binary scientific notation as a product of: A value x such that 12 ≤ x < 102 and a A power 102 Add the bias to the exponent to obtain the biased exponent field value Write the mantissa by Dropping the leading “1” (to the left of the binary point) Extending or rounding the remaining to 23-bits 11/21/2018 Copyright, G. A. Tagliarini, PhD

13 IEEE 754 Conversion Example
Convert 1 3/16 Sign bit = 0 1 3/16 = = x (102)02 Biased exponent = = Mantissa = (note that the leading “1” has been omitted and trailing zeros added to create a total of 23 bits) Completed representation or 3F 11/21/2018 Copyright, G. A. Tagliarini, PhD

14 IEEE 754 Conversion Example 2
Convert Sign bit = 1 3.110 = …2 = …2 x (102)12 Biased exponent = = Mantissa = (note that the leading “1” has been omitted, repeating digits used and the representation rounded to a total of 23 bits) Completed representation or C 11/21/2018 Copyright, G. A. Tagliarini, PhD

15 What Difference Does It Make?
Patriot Missile Failure (28 killed, 100 injured) Ariane 5 Explosion ($7 Billion) 11/21/2018 Copyright, G. A. Tagliarini, PhD

16 Some IEEE 754 Floating Point Values
Sign Bit Exponent Field Mantissa Floating Point Value 1.0 1.0 + eM 2.0 2.0*(1.0 + eM) 4.0 4.0*(1.0 + eM) 8.0 8.0*(1.0 + eM) 11/21/2018 Copyright, G. A. Tagliarini, PhD

17 Some IEEE 754 Floating Point Values
SignBit Exponent Field Mantissa Interpretation +0.0 1 -0.0 +∞ -∞ xxxx xxxx xxxx xxxx xxxx xxx (at least one x≠0) NaN eMax=2+127*(2-2-23) ≈2+128 eMin=2-126*2-23=2-149 11/21/2018 Copyright, G. A. Tagliarini, PhD

18 Some Notes About IEEE 754, Floating Point Representation
The density of the distribution of floating point values varies along the number line Half of the possible floating point values lie in the interval [-1, 1] For single precision representation Machine epsilon εM = 2-23 The minimum representable value εMin = 2-149 The maximum representable value εMax ≈ 2128 11/21/2018 Copyright, G. A. Tagliarini, PhD

19 Finding Machine Epsilon, εM
Set εM = 1 Do εM = εM/2 x = 1 + εM While (x>1) εM = 2*εM 11/21/2018 Copyright, G. A. Tagliarini, PhD

20 Copyright, G. A. Tagliarini, PhD
Errors Round-off Arise from limitations in the space allocated for representing specific type of datum Truncation Arise from abbreviating an analytical representation 11/21/2018 Copyright, G. A. Tagliarini, PhD

21 Copyright, G. A. Tagliarini, PhD
Random Numbers Uniform random distribution (e.g., Math.random()) For u1 and u2 are chosen from a uniform distribution, then have a Gaussian distribution 11/21/2018 Copyright, G. A. Tagliarini, PhD


Download ppt "Introduction to Scientific Computation"

Similar presentations


Ads by Google