Lecture05

# Lecture05 - 0306-381 Applied Programming • Finding Roots...

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 0306-381 Applied Programming • Finding Roots • Floating-Point Representation Determination of Multiple Roots • f (x) has a root r of multiplicity p f (x) = (x - r)pg(x) • Even multiple roots: p even – Problematic for Secant and Newton’s – Divide by “derivative”: 0 at the even multiple root • Slower convergence for multiple roots – Secant and Newton’s – Linear convergence • Two modifications to Newton’s method for faster convergence at multiple root – Scale by root multiplicity p – Use alternate function 2 Newton’s Modification for Multiple Roots: Scale by Root Multiplicity • f (x) has a root r of multiplicity p f (x) = (x - r)pg(x) • Original Newton’s method f ( xi ) xi +1 = xi f ¢( xi ) • Modification f ( xi ) xi +1 = xi - p f ¢( xi ) Quadratic convergence 3 Newton’s Modification for Multiple Roots: Use Alternate Function • Original Newton’s method f ( xi ) xi +1 = xi f ¢( xi ) • Alternate function g(x) f ( xi ) g ( x) = f ¢( xi ) Roots at same location(s) as f (x) • Modification g ( xi ) xi +1 = xi g ¢( xi ) 4 Muller’s Method Example Used with permission from support materials for Applied Numerical Methods for Engineers and Scientists, S. S. Rao, Prentice Hall, 2002. 5 Muller’s Method t1 = p1 - p3 , t 2 = p2 - p3 , t3 = p3 - p3 a= t 2 ( f1 - f 3 ) - t1 ( f 2 - f 3 ) 2 t 2 t12 - t1t 2 2 t2 ( f1 - f 3 ) - t12 ( f 2 - f 3 ) b= 2 t1t 2 - t 2 t12 c = f3 - b ± b 2 - 4ac Roots = 2a - 2c = b ± b 2 - 4ac p4 = p3 + SmallRoot Used with permission from S. Jay Yang, Dept. of Computer Engineering, RIT. 6 0306-381 Applied Programming • Finding Roots FFloating-Point Representation C Floating-Point Numbers (Platform Dependent) Intel processors (in general) • float IEEE-754 single precision (32 bits) • double IEEE-754 double precision (64 bits) • long double Intel IA-32 double extended precision (80 bits, but may be stored in 96 or 128 bits) 8 Floating-Point Nomenclature Decimal Scientific Notation X = a ´ 10b – a: Significand or mantissa – b: Exponent • Binary Scientific Notation X = a ´ 2b – a: Binary significand or mantissa – b: Binary exponent Basis of binary floating-point representations 9 IEEE-754 Single Precision • Value = (-1)S ´ 2E-127 ´ 1.F – S: sign – E: biased exponent – F: fractional part of significand (normalized) • 32 bits 1 bit 8 bits 23 bits S 31 E 23 F 0 10 IEEE-754 Double Precision • Value = (-1)S ´ 2E-1023 ´ 1.F – S: sign – E: biased exponent – F: fractional part of significand (normalized) • 64 bits 1 bit 11 bits 52 bits S 63 E 52 F 0 11 Intel IA-32 Double Extended-Precision • Value = (-1)S ´ 2E-16383 ´ I.F – S: sign – E: biased exponent – I: integer part of significand • 1: normalized numbers, infinities, and NaNs • 0: denormalized numbers and zero – F: fractional part of significand • 80 bits 1 bit 15 bits 1 bit 63 bits S 79 E 64 I 63 F 0 12 Accessing IEEE-754 SP Data • Access floating-point number • Access individual components – S: sign – E: biased exponent – F: fractional part of significand (normalized) • Access raw data word (32 bits) – Binary – Hexadecimal Use C union 13 Union for Floating-Point Value and Data Word Access /* Type for direct access to both IEEE-754 SP value and */ /* raw data word */ typedef union { float FP; unsigned int Word; } FP_IEEE_SP; ... FP_IEEE_SP Number; ... Number.FP = 0.75; printf (“Number hex data: Storage allocation for union: • Maximum of field sizes – sizeof (float): 4 – sizeof (int): 4 • All fields begin at same address 0x%08X\n”, Number.Word); Number hex data: 0x3F400000 14 Bit-Mapped Structure • struct specifying bits per field • Storage allocation – Order • Compiler • Machine – Total bits • At least sum of bits specified • Perhaps more than specified bits 15 /* Bit-mapped type */ /* for access to */ /* IEEE-754 SP fields */ typedef struct { unsigned int F:23; unsigned int E:8; unsigned int S:1; } FP_IEEE_SP_Fields; Union for Accessing Floating-Point Value, Data Word, and IEEE-754 Fields (Single Precision) /* Type for direct */ /* access to IEEE-754 */ /* SP value, fields, */ /* and raw data word */ typedef union { Number hex data: 0x3F400000 float FP; FP_IEEE_SP_Fields Field; Number fields: unsigned int Word; S: 0 } FP_IEEE_SP; E: 7E ... FP_IEEE_SP Number; M: 0x400000 ... Number.FP = 0.75; printf (“Number hex data: 0x%08X\n”, Number.Word); printf (“Number fields:\n S: %d\n E: 0x%02X\n F: 0x%06X\n”, Number.Field.S, Number.Field.E, Number.Field.F); 16 C Floating-Point Number Formats (Platform Dependent) cluster.ce.rit.edu • float IEEE-754 single precision (32 bits) • double IEEE-754 double precision (64 bits) • long double Intel double extended-precision format (80 bits) complies with IEEE-754 extended double precision – sizeof (long double) ® 16 bytes = 128 bits – upper 6 bytes (48 bits) are padding 17 IEEE-754 Special Representations Zero, infinity, and not a number (NaN) • ± 0 (zero) –E=0 –F=0 • ± ¥ (infinity) – E = Maximum value –F=0 • NaN (not a number) – E = Maximum value –F¹0 18 ...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online