ma/cs375 fall 2002 1 ma/cs 375 fall 2002 lecture 8

27
MA/CS375 Fall 2002 1 MA/CS 375 Fall 2002 Lecture 8

Upload: milton-nash

Post on 21-Jan-2016

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: MA/CS375 Fall 2002 1 MA/CS 375 Fall 2002 Lecture 8

MA/CS375 Fall 2002 1

MA/CS 375

Fall 2002

Lecture 8

Page 2: MA/CS375 Fall 2002 1 MA/CS 375 Fall 2002 Lecture 8

MA/CS375 Fall 2002 2

Matlab Built-in Derivative Routines

• diff takes the derivative of a function of one variable sampled at a set of discrete points

• gradient takes the x and y derivatives of a function of two variables

Page 3: MA/CS375 Fall 2002 1 MA/CS 375 Fall 2002 Lecture 8

MA/CS375 Fall 2002 3

diffdemo.m

Using diff on

F = x^3

diff

Page 4: MA/CS375 Fall 2002 1 MA/CS 375 Fall 2002 Lecture 8

MA/CS375 Fall 2002 4

Page 5: MA/CS375 Fall 2002 1 MA/CS 375 Fall 2002 Lecture 8

MA/CS375 Fall 2002 5

diff

diffdemo.m

Using diff on

F = sin(x)

Page 6: MA/CS375 Fall 2002 1 MA/CS 375 Fall 2002 Lecture 8

MA/CS375 Fall 2002 6

Page 7: MA/CS375 Fall 2002 1 MA/CS 375 Fall 2002 Lecture 8

MA/CS375 Fall 2002 7

Explanation of Error Curve

• We can find good reason for the shape of the error curve..

Page 8: MA/CS375 Fall 2002 1 MA/CS 375 Fall 2002 Lecture 8

MA/CS375 Fall 2002 8

Recall: Taylor’s Theorem With Cauchy Remainder

2( )

11 *

*for some

' ''( ) ... ( )2! !

1 !

,

nn

n

nn

n

f x f x f x f x f x Rn

R f xn

x x x

1) Taylor’s theorem with Cauchy Remainder:

Here Rn is the Cauchy Remainder

Page 9: MA/CS375 Fall 2002 1 MA/CS 375 Fall 2002 Lecture 8

MA/CS375 Fall 2002 9

Recall: Taylor’s Theorem With Cauchy Remainder

1

22 *

1

*for some

'

2!

,

f x f x f x R

R f x

x x x

2) Using a first order expansion (n=1)

Page 10: MA/CS375 Fall 2002 1 MA/CS 375 Fall 2002 Lecture 8

MA/CS375 Fall 2002 10

Introducing Finite Precision Errors

ˆˆ ˆ

( )

y x

x O

3) round off due to finite precision representation of x and delta

4) round off due to finite precision computation of f

ˆ ˆ ˆ ( )

( )

f y f y O

f x O

Page 11: MA/CS375 Fall 2002 1 MA/CS 375 Fall 2002 Lecture 8

MA/CS375 Fall 2002 11

2*

2*

ˆ ˆˆ ˆ

' ''2

' ''2

f y f x f y f x O

f x f x f x f x O

f x f x O

Putting It All Together

Page 12: MA/CS375 Fall 2002 1 MA/CS 375 Fall 2002 Lecture 8

MA/CS375 Fall 2002 12

*

*for some

ˆ ˆ ˆˆ ˆ' ''

ˆ 2

,

f x f xf x f x O

x x x

Final Result

Page 13: MA/CS375 Fall 2002 1 MA/CS 375 Fall 2002 Lecture 8

MA/CS375 Fall 2002 13

*

*for some

ˆ ˆ ˆˆ ˆ' ''

ˆ 2

,

f x f xf x f x O

x x x

Analysis of Final Result

In words: the error created by approximating the derivative of f by the first order formula is given by two terms

First term proportional to delta times the secondderivative of f at some point between x and (x plus delta)

Second term is due to finite precision representation off, x, delta

Page 14: MA/CS375 Fall 2002 1 MA/CS 375 Fall 2002 Lecture 8

MA/CS375 Fall 2002 14

Finding the Gradient of Two-dimensional Functions

Page 15: MA/CS375 Fall 2002 1 MA/CS 375 Fall 2002 Lecture 8

MA/CS375 Fall 2002 15

Definition of Partial Derivatives• Given a function f of two variables x,y

• We define the two partial derivatives by

0

, ,, lim

f x y f x yfx y

x

0

, ,, lim

f x y f x yfx y

y

Page 16: MA/CS375 Fall 2002 1 MA/CS 375 Fall 2002 Lecture 8

MA/CS375 Fall 2002 16

Using gradient on

F = x^2

gradientdemo.m

gradient

Page 17: MA/CS375 Fall 2002 1 MA/CS 375 Fall 2002 Lecture 8

MA/CS375 Fall 2002 17

Page 18: MA/CS375 Fall 2002 1 MA/CS 375 Fall 2002 Lecture 8

MA/CS375 Fall 2002 18

Using gradient on

F = x^2+y^2

gradientdemo1.m

Page 19: MA/CS375 Fall 2002 1 MA/CS 375 Fall 2002 Lecture 8

MA/CS375 Fall 2002 19

Page 20: MA/CS375 Fall 2002 1 MA/CS 375 Fall 2002 Lecture 8

MA/CS375 Fall 2002 20

Using gradient on

F = (x^2)*(y^2)

gradientdemo2.m

Page 21: MA/CS375 Fall 2002 1 MA/CS 375 Fall 2002 Lecture 8

MA/CS375 Fall 2002 21

Page 22: MA/CS375 Fall 2002 1 MA/CS 375 Fall 2002 Lecture 8

MA/CS375 Fall 2002 22

Using gradient on

F = (sin(pi*x))*(cos(pi*y))

gradientdemo3.m

Page 23: MA/CS375 Fall 2002 1 MA/CS 375 Fall 2002 Lecture 8

MA/CS375 Fall 2002 23

Page 24: MA/CS375 Fall 2002 1 MA/CS 375 Fall 2002 Lecture 8

MA/CS375 Fall 2002 24

Individual Class Exercise Part 1

1) Using the following formula compute the approximate derivative of: f=x.^5 at 1000 points between x=-1 and 1 with delta = 1e-4

f x f xdfdx

Do not use diff

Page 25: MA/CS375 Fall 2002 1 MA/CS 375 Fall 2002 Lecture 8

MA/CS375 Fall 2002 25

Individual Class Exercise Part 22) Plot the error defined by:

actualerror = abs(dfdx-5*x.^4);

3) On the same graph plot the error defined by:

guesserror = abs(delta*(5*4*x.^3)/2);

4) Write comments on the graph about what you see.

5) Label the axes. Add a title to the graph. Add a legend to the graph.

Page 26: MA/CS375 Fall 2002 1 MA/CS 375 Fall 2002 Lecture 8

MA/CS375 Fall 2002 26

Individual Class Exercise Part 3

• Repeat on separate graphs for:delta = 1e-6, 1e-8, 1e-10, 1e-15

• Explain what you see on each graph.

• Hand this in at the start of next lecture (Monday 09/09/02). This will be graded.

• Remember to include your name and staple.

Page 27: MA/CS375 Fall 2002 1 MA/CS 375 Fall 2002 Lecture 8

MA/CS375 Fall 2002 27

Summary

• We have narrowed down the error term to two concretely defined terms

• Next time we will use these ideas to find edges in images.