CSE 541 Numerical Methods - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

CSE 541 Numerical Methods

Description:

Problem: Compute f(x) Easy for well known functions. For ... 'What goes up, must come down' f(x) a. b. f'( ) = 0. 9/24/09. 14. CSE 541 - Numerical Methods ... – PowerPoint PPT presentation

Number of Views:68
Avg rating:3.0/5.0
Slides: 22
Provided by: rogerc2
Category:

less

Transcript and Presenter's Notes

Title: CSE 541 Numerical Methods


1
CSE 541Numerical Methods
  • Taylors Series, Taylors Theorem, Mean-Value
    Theorem, Rolles Theorem

2
Function Evaluation (1)
  • Problem Compute f(x)
  • Easy for well known functions
  • For example, f (x) 1, f (x) x2

3
Function Evaluation (2)
  • Suppose f (x) is a black box
  • Difficult and/or expensive to compute
  • For example a complex function, an experiment, a
    procedure
  • Limited information about the function
  • Suppose we know information about the function at
    a particular domain location, x c
  • f (c), f (c), f (c), f (c),

4
Taylors Series
  • Evaluate f (x) about a point c, called the point
    of expansion
  • Observations
  • An infinite series
  • (x c) is the distance from the point of
    expansion
  • F (x) is a polynomial!!!

5
Taylors Theorem
  • Where do we truncate this series?
  • Taylors Theorem states the following

6
Taylors Theorem
  • Observations
  • (x - c)(n 1) ? 0, if x - cltlt 1
  • (x - c)(n 1) ? quickly, if x - cgtgt 1
  • Higher-order derivatives may get smaller, e.g.
    smooth functions).

7
Some Common Derivatives
8
Some Resulting Series
  • About c 0, called Maclaurin Series

9
Some Resulting Series
  • About c 0

10
Books Introduction Example
  • Eight terms for first series not even yielding a
    single significant digit.
  • Only four for second serieswith
    foursignificantdigits.

11
Mean-Value Theorem
  • A special case of Taylors Theorem
  • Take two locations x a and x b, where (a, b)
    is an interval.
  • Assume f(x) is continuous and its first
    derivative exists everywhere within (a, b).
  • Take Taylors Theorem where the point of
    expansion is a, x b, and n 0.

12
Mean-Value Theorem
  • There exists a location ? in the interval (a, b)
    where the first derivative is equal to the secant

secant
f(x)
a
b
?
13
Rolles Theorem
  • A special case of the Mean-Value Theorem
  • If a and b are roots of function f (x), i.e. f
    (a) f (b) 0, then f (?)0 for some point ? in
    (a, b).
  • What goes up, must come down

f(x)
f(?) 0
?
a
b
14
Caveats
  • For Taylors Series and Taylors Theorem to hold,
    the function and its derivatives must exist
    within the range you are trying to use it
  • The function cant change its current value
    faster than the derivative will allow
  • So, the function does not go to infinity, or have
    a discontinuity (implies f(x) does not exist),

15
Implement a Fast sin()Application Riemann Sum
  • const int Max_Iters 100,000,000
  • float x -0.1
  • float delta 0.2 / Max_Iters
  • float Reimann_sum 0.0
  • for (int i 0 i lt Max_Iters i)
  • Reimann_Sum sinf(x)
  • x delta
  • Printf(Integral of sin(x) from 0.1-gt0.1 equals
    f\n, Reimann_Sumdelta )

16
Implement a Fast sin()
  • const int Max_Iters 100,000,000
  • float x -0.1
  • float delta 0.2 / Max_Iters
  • float Reimann_sum 0.0
  • for (int i 0 i lt Max_Iters i)
  • Reimann_Sum my_sin(x) //my own sine func
  • x delta
  • Printf(Integral of sin(x) from 0.1-gt0.1 equals
    f\n, Reimann_Sumdelta )

17
Version 1.0 Taylors
  • my_sin( const float x )
  • float x2 xx
  • float x3 xx2
  • return (x x3/6.0 x2 x3/120.0 )

Use three terms of the Taylors series expansion
for sin(x)
18
Version 2.0 Horners Rule
  • Static const float fac3inv 1.0 / 6.0f
  • Static const float fac5inv 1.0 / 120.0f
  • my_sin( const float x )
  • float x2 xx
  • return x(1.0 x2(fac3inv - x2fac5inv))

19
Version 3.0 Inline code
  • const int Max_Iters 100,000,000
  • float x -0.1
  • float delta 0.2 / Max_Iters
  • float Reimann_sum 0.0
  • for (i 0 i lt Max_Iters i)
  • x2 xx
  • Reimann_Sum x(1.0 x2(fac3inv -
    x2fac5inv)
  • x delta
  • Printf(Integral of sin(x) from 0.1-gt0.1 equals
    f\n, Reimann_Sumdelta )

20
Timings
  • Pentium III, 600MHz machine

21
Observations
  • Is the result correct?
  • Why did we gain some accuracy with version 2.0?
  • Is (0.1, 0.1) a fair range to consider?
  • Is the original sinf() function optimized?
  • How did we achieve our speed-ups?
Write a Comment
User Comments (0)
About PowerShow.com