ma/cs375 fall 2002 1 ma/cs 375 fall 2002 lecture 8
TRANSCRIPT
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
MA/CS375 Fall 2002 3
diffdemo.m
Using diff on
F = x^3
diff
MA/CS375 Fall 2002 4
MA/CS375 Fall 2002 5
diff
diffdemo.m
Using diff on
F = sin(x)
MA/CS375 Fall 2002 6
MA/CS375 Fall 2002 7
Explanation of Error Curve
• We can find good reason for the shape of the error curve..
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
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)
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
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
MA/CS375 Fall 2002 12
*
*for some
ˆ ˆ ˆˆ ˆ' ''
ˆ 2
,
f x f xf x f x O
x x x
Final Result
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
MA/CS375 Fall 2002 14
Finding the Gradient of Two-dimensional Functions
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
MA/CS375 Fall 2002 16
Using gradient on
F = x^2
gradientdemo.m
gradient
MA/CS375 Fall 2002 17
MA/CS375 Fall 2002 18
Using gradient on
F = x^2+y^2
gradientdemo1.m
MA/CS375 Fall 2002 19
MA/CS375 Fall 2002 20
Using gradient on
F = (x^2)*(y^2)
gradientdemo2.m
MA/CS375 Fall 2002 21
MA/CS375 Fall 2002 22
Using gradient on
F = (sin(pi*x))*(cos(pi*y))
gradientdemo3.m
MA/CS375 Fall 2002 23
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
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.
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.
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.