Answer to Quiz 11 Fri 20 Apr 2007

  1. The central difference approximation for the derivative of a function f at x is defined by the formula y = (f(x+h) - f(x-h))/(2h), for h > 0.

    1. Write a MATLAB function centdiff which takes on input f, x, and h, and which returns in y the central difference approximation for f'(x). Complete
      function y = centdiff(f,x,h)
      %
      %  The function y = centdiff(f,x,h) returns the central difference
      %  approximation for the derivative of f at x, using step size h.
      %
      
    2. Give the MATLAB command to use centdiff to approximate the derivative of sin(x) for x = 1.3 using h = 0.01. Give the value returned by your centdiff.

    Answer:

    1. the completion of the function:
               y = ( feval(f,x+h) - feval(f,x-h) ) / ( 2*h );
      
    2. the function call and its value:
               centdiff('sin',1.3,0.01)
      	                             0.2675
      
  2. Give all MATLAB commands to make a surface of revolution, around the vertical axis. Revolute r = exp(t) for t in [0,1] around the vertical axis.
    Sketch the surface you obtain.

    Answer:

                    t = 0:0.01:1;
                    r = exp(t);
                    cylinder(t);
    
    % see the paper handout for the sketch...