MA/CS375 Fall MA/CS 375 Fall 2002 Lecture 8
MA/CS375 Fall 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 diffdemo.m Using diff on F = x^3 diff
MA/CS375 Fall
5 diff diffdemo.m Using diff on F = sin(x)
MA/CS375 Fall
7 Explanation of Error Curve We can find good reason for the shape of the error curve..
MA/CS375 Fall Recall: Taylor’s Theorem With Cauchy Remainder 1) Taylor’s theorem with Cauchy Remainder: Here R n is the Cauchy Remainder
MA/CS375 Fall Recall: Taylor’s Theorem With Cauchy Remainder 2) Using a first order expansion (n=1)
MA/CS375 Fall Introducing Finite Precision Errors 3) round off due to finite precision representation of x and delta 4) round off due to finite precision computation of f
MA/CS375 Fall Putting It All Together
MA/CS375 Fall Final Result
MA/CS375 Fall 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 second derivative of f at some point between x and (x plus delta) Second term is due to finite precision representation of f, x, delta
MA/CS375 Fall Finding the Gradient of Two- dimensional Functions
MA/CS375 Fall Definition of Partial Derivatives Given a function f of two variables x,y We define the two partial derivatives by
MA/CS375 Fall Using gradient on F = x^2 gradientdemo.m gradient
MA/CS375 Fall
MA/CS375 Fall Using gradient on F = x^2+y^2 gradientdemo1.m
MA/CS375 Fall
MA/CS375 Fall Using gradient on F = (x^2)*(y^2) gradientdemo2.m
MA/CS375 Fall
MA/CS375 Fall Using gradient on F = (sin(pi*x))*(cos(pi*y)) gradientdemo3.m
MA/CS375 Fall
MA/CS375 Fall 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 Do not use diff
MA/CS375 Fall Individual Class Exercise Part 2 2) 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 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 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.