Docsity

Floating Points, Root Finding - Lecture Notes | CS 257, Study notes of Computer Science

Partial preview of the text

Download Floating Points, Root Finding - Lecture Notes | CS 257 and more Study notes Computer Science in PDF only on Docsity!

Lecture 4

Floating Points, Rootfinding

L. Olson

Department of Computer Science University of Illinois at Urbana-Champaign

September 6, 2006

Catastrophic Cancellation

Adding c = a + b will result in a large error if a  b a  b Let

a = x.xxx · · · × 100 b = y.yyy · · · × 10 −^8

Then

︷ finite precision︸︸ ︷ x.xxx xxxx xxxx xxxx

  • 0 .000 0000 yyyy yyyy yyyy yyyy = x.xxx xxxx zzzz zzzz ???? ????︸ ︷︷ ︸ lost precision

Summary

addition: c = a + b if a  b or a  b subtraction: c = a − b if a ≈ b catastrophic: caused by a single operation, not by an accumulation of errors can often be fixed by mathematical rearrangement

Loss of Significance

Example

x = 0 .37214 48693 and y = 0 .37202 14371. What is the relative error in x − y in a computer with 5 decimal digits of accuracy? |x − y − (x¯ − ¯y)| |x − y|

≈ 3 × 10 −^2

Loss of Significance

Example

Consider x = 37. 593621 and y = 37. 584216.

2 −^11 < 1 − y x

= 0 .00025 01754 < 2 −^12

So we lose 11 or 12 bits in the computation of x − y. yikes!

Example

Back to the other example (5 digits): x = 0. 37214 and y = 0. 37202.

10 −^4 < 1 − y x

= 0. 00032 < 10 −^5

So we lose 4 or 5 bits in the computation of x − y. Here, x − y = 0. 00012 which

has only 1 significant digit that we can be sure about

Loss of Significance

So what to do? Mainly rearrangement.

f (x) =

x^2 + 1 − 1

Problem at x ≈ 0. One type of fix:

f (x) =

x^2 + 1 − 1

) (^ √x (^2) + 1 + 1 √ x^2 + 1 + 1

= x

2 √ x^2 + 1 + 1 no subtraction!

Recall

Then the function can be expressed as the nth^ Taylor Series approximation and a truncation error:

f (x) = fn(x) + Rn(x)

= f (x 0 ) + (x − x 0 ) df dx |x=x^0 +

(x − x 0 )^2 2

d^2 f dx^2 |x=x^0 +^ · · ·^ +

(x − x 0 )n n!

dnf ︸ ︷︷ dxn^ |x=x︸^0 fn(x)

  • (x^ −^ x^0 )

n+ 1 (n + 1 )!

dn+^1 f dxn+^1 |x=ξ ︸ ︷︷ ︸ Rn(x)

Convergence

Since d n+ (^1) f dxn+^1 is continuous on^ [a,^ b]^ it is bounded, so

Rn(x) = O( (x^ −^ x^0 )

(n+ 1 ) (n + 1 )! ) = O(hn+^1 )

We say that the truncation error is of ”order n + 1 ”

Questions: (^1) how fast does the approximation converge? (^2) how expensive is it to compute the approximation? (later)

More General

Convergence rate

Let {yn}∞ n= 1 be a sequence:

y 0 , y 1 , y 2 ,... , yj,...

If α and K exist so that |y − yn| 6 K nα Then we say that {yn} converges to y with rate of convergence (^) n^1 α So we expect |en| = |y − yn| ≈ c (^) n^1 α

Convergence

Then |en+ 1 | |en| ≈^ constant In general, a sequence is said to converge with rate r if

k^ lim→∞

|en+ 1 | |en|r^ =^ C

Special Cases:

If r = 1 and C < 1 , then the rate is linear If r > 1 , then the rate is superlinear If r = 2 and C < 1 , then the rate is quadratic If r = 3 and C < 1 , then the rate is cubic

What Next?

We need to study some iterations. iteratively finding a root to an equation iteratively finding the solution to an algebraic system iteratively finding solutions to Ordinary Differential Equations (ODEs) ...

Planetary Motion

Courtesy of G. Wright

Consider a planet in orbit around the sun ω is the frequency of orbit t is the time since the planet was last closest to the sun (perifocus) e =

1 − b a^22 is the eccentricity of the orbit Kepler’s Law say the location of the planet at time is

x = a(cos E − e) y = a

1 − e^2 sin E

E = ωt + e sin E is the eccentric anomaly cannot explicitly express E

Root Finding

Given a function f (x), find x so that f (x) = 0

Rootfinding

Goals: Find roots to equations Compare usability of different methods Compare convergence properties of different methods (^1) bracketing methods (^2) Bisection Method (^3) Newton’s Method (^4) Secant Method (^5) (opt) fixed point iterations (^6) (opt) special Case: Roots of Polynomials