Review for Exam II (with answers)

The questions below are meant to stimulate the preparation of the exam. They cover some of the most important but not all topics. You must review all course materials: textbook, homework exercises, lecture notes (also consult the course web site), and quizzes.

Answers to Exam 2 Spring 05:

Answers to Exam 2 Fall 03:

Answers to Exam 2 Spring 2002:

You may use a formula sheet: postscript version , and version in pdf format .

  1. Show that
                   n
                  ---
          p(x) =  >     l (x) f
                  ---    i     i
                  i=0
    
    with
                   n    x - x
                  ---        j
          l (x) = | |   -----
           i      j=0   x - x
                  j/=i   i   j
    
    satisfies
    
          p(x ) = f    for i = 0,1,..,n.
             i     i
    

    Answer:

    Observe that l_i(x_j) = 0 for j /= i, because there is one factor in the numerator that is zero. Furthermore, we see that l_i(x_i) = 1 because numerator and denominator are equal to each other. These observations imply p(x_i) = f_i, i = 0,1,2,..,n.

  2. Consider the polynomial p(x) = x^2 - 5x + 1.

    1. Construct the Newton form of p(x) by divided differences, using the points (x[i],p(x[i])), with x[i] = i, for i=0,1,2,3.

    2. Explain why the last element f[0123] in the table of divided differences you constructed above is (or should have been) zero.

    3. Apply Neville's algorithm to evaluate the interpolating polynomial at 0.5.

    4. Approximate p(x) with the linear function that minimizes the squares of the errors, using the points (x[i],p(x[i])), with x[i] = i, for i=0,1,2,3.

    Answers:

    1.       0   1
                    -3 - 1
                    ------- = -4
                     1 - 0
                                   -3-(-4)
            1  -3                  ------- = 1
                    -5 - 1           2-1
                    ------- = -3                   1-1
                     2 - 0                        ----- = 0
                                   -2-(-4)         3-2
            2  -5                  ------- = 1
                    -5 - 1           3-1
                    ------- = -2
                     3 - 0
      
            3  -5 
      
         The Newton form is
      
            f_0 + f_01*(x-x[0]) + f_012*(x-x[0])*(x-x[1])
                + f_0123*(x-x[0])*(x-x[1])*(x-x[2])
      
          = 1 + (-4)*(x-0) + 1*(x-0)*(x-1) + 0*(x-0)*(x-1)*(x-2)
          = 1 - 4*x + x*(x-1)
      

    2. The interpolating polynomial is unique. If f[0123] would not be zero, the interpolating polynomial would be of degree three. But this contradicts with the given polynomial, which is of course also interpolating, and of degree two. Thus we would have two different interpolating polynomials (one of degree two and one of degree three), which is impossible. Therefore, f[0123] must be zero.

    3.      0    1
                     p
                      01
           1   -3           p
                     p       012
                      12           p
           2   -5           p       0123
                     p       123
                      23
           3   -5
      
      with
                  (1/2 - 1)*1 - (1/2 - 0)*(-3)
           p   = ------------------------------ = -1
            01              0 - 1
      
                  (1/2 - 2)*(-3) - (1/2 - 1)*(-5)
           p   = --------------------------------- = -2
            12                  1 - 2
      
                  (1/2 - 3)*(-5) - (1/2 - 2)*(-5)
           p   = --------------------------------- = -5
            23                  2 - 3 
      
                   (1/2 - 2)*(-1) - (1/2 - 0)*(-2)
           p    = --------------------------------- = -5/4
            012                 0 - 2 
      
                   (1/2 - 3)*(-2) - (1/2 - 1)*(-5)
           p    = --------------------------------- = -5/4
            123                 1 - 3 
      
                    (1/2 - 3)*(-5/4) - (1/2 - 0)*(-5/4)
           p     = ------------------------------------- = -5/4
            0123                   0 - 3 
      
      
      Thus p(0.5) = -5/4. Notice that, since we are interpolating a second degree polynomial with four points, we already see the final result appearing twice in the next to last column.

    4. Let y = a*x + b denote the linear function with unknown coefficients a and b. To determine a and b we solve the overdetermined linear system:
               1 = a*0 + b
              -3 = a*1 + b
              -5 = a*2 + b
              -5 = a*3 + b
      
      or in matrix notation:
      
             [ 0 1 ]         [  1 ]
             [ 1 1 ] [ a ] = [ -3 ]
             [ 2 1 ] [ b ]   [ -5 ]
             [ 3 1 ]         [ -5 ]
      
                X    [ a ] = f
                     [ b ] 
      
      To solve the system in the least squares sense,
      we set up the normal equations:
      
          T
         X *X = [ 0 1 2 3 ] [ 0 1 ] = [ 14  6 ]
                [ 1 1 1 1 ] [ 1 1 ]   [  6  4 ]
                            [ 2 1 ]
                            [ 3 1 ] 
      
          T
         X *f = [ 0 1 2 3 ] [  1 ] = [ -28 ]
                [ 1 1 1 1 ] [ -3 ]   [ -12 ]
                            [ -5 ]
                            [ -5 ]
                                     T            T
      The solution to the system    X *X [ a ] = X *f
                                         [ b ] 
      is a = -2 and b = 0.
      

  3. The Maclaurin expansion of tan(x) is
                           1   3    2   5    17   7     62   9      10
             tan(x) = x + --- x  + --- x  + ---- x  + ----- x  + O(x  )
                           3        15       315       2835
    
    Use this Maclaurin expansion to construct a Padé approximation for tan(x) as a quotient of two quadrics.

    Answer:

      (            2     1   3      4 )   (              2 )   (              2 )
      ( 0 + x + 0 x  +  --- x  + 0 x  ) * ( 1 + b x + b x  ) - ( a + a x + a x  ) 
      (                  3            )   (      1     2   )   (  0   1     2   )
    
    expanding product:
    
             2      3
      x + b x  + b x
           1      2
    
                  1   3    1     4    1     5
               + --- x  + --- b x  + --- b x
                  3        3   1      3   2
    
    setting coefficients to consecutive powers of x to zero:
    
      0
     x  :  0 - a  = 0
                0 
      1
     x  :  1 - a  = 0
                1
    
      2
     x  :  b  - a  = 0
            1    2
    
      3          1
     x  :  b  + --- = 0
            2    3
    
      4     1
     x  :  --- b  = 0
            3   1
    
    we solve this system: 
    
                      1
      b  = 0   b = - ---   a  = 0   a  = 1   a  = 0
       1        2     3     0        1        2
    
    Thus our approximation is
    
                     x
              ---------------
                       1   2
                1  -  --- x
                       3
    

  4. Consider
                2
               x  + 3 x - 1
       r(x) = --------------
                  2
                 x   -  1
    

    1. Compute a continued-fraction representation of r(x).

    2. Count the number of arithmetical operations you need to evaluate the continued-fraction representation of r(x). Compare this number with the number of arithmetical operations needed to evaluate r(x) if you would use the Horner form of the numerator and denominator of r(x).

    Answers :

    1.         2            |   2
             x  + 3 x - 1  |  x  - 1
              2            |----------
         - ( x        - 1)   1  
         -----------------
                  3 x
      
              2                  2
             x  + 3 x - 1 = 1 ( x  - 1 ) + 3 x
      
      
                          3 x             3
           r(x) = 1 + ---------- = 1 + ---------
                         2               2
                        x  - 1          x  - 1
                                       --------
                                           x
              2     |
             x  - 1 |  x
              2     |-------
           - x        x
           ---------
                - 1
      
              2
             x  - 1 = x x - 1
      
         
                         3
          r(x) = 1 + -----------
                             1
                      x  -  ---
                             x
      
      
    2. The evaluation of the continued-fraction representation requires two divisions, one addition and one subtraction.

      Compared to the cost of evaluating the Horner form of numerator and denominator:

           2
          x  + 3 x - 1     (x + 3)*x - 1
         -------------- = ---------------
              2            (x + 0)*x - 1
             x  - 1
      
      we see that the evaluation takes two multiplications, one division, two additions, and two subtractions. Even if we disregard the +0, the continued-fraction representation is more efficient to evaluate than the quotient of Horner forms.

    1. Explain why (f(x+h) - f(x))/h is a first-order approximation for f'(x).

    2. Explain why (f(x+h) - f(x-h))/(2h) is a second-order approximation for f'(x).

    Answers:

    1.    f(x+h) = f(x) + h*f'(x) + h^2*f''(x) + ...
      
         f(x+h) - f(x)
        --------------- = f'(x) + h*f''(x) + ...
               h
      
    2.                   f(x+h) - f(x-h)
        delta f(x,h) = -----------------  is an even function of h
                              2 h
      
                         f(x-h) - f(x+h)
        delta f(x,-h) = ----------------- = delta f(x,h)
                             - 2 h
      
      
      Because delta f(x,h) is an even function of h, only even powers of h occur if we expand delta f(x,h) in powers of h. Thus the power series start at h^2, and delta f(x,h) is a second-order approximation for the derivative of f at x.

    1. Use forward differences to compute a first-order approximation for the third derivative of f(x).

    2. Use central differences to compute a second-order approximation for the third derivative of f(x).

    Answers:

    1.                     f(x+h) - f(x)
         Delta f(x,h) =  ---------------
                                 h
      
      
                          f(x+2h) - f(x+h)       f(x+h) - f(x)
                         ------------------  -  ---------------
              2                   h                     h
         Delta f(x,h) =  --------------------------------------
                                             h
      
                          f(x+2h) - 2 f(x+h) + f(x)
                      =  ---------------------------
                                      2
                                     h
      
      
              3           f(x+3h) - f(x+2h)       f(x+2h) - f(x+h)     f(x+h) - f(x)
         Delta f(x,h) =  ------------------- - 2 ------------------ + ---------------
                                   3                      3                   3
                                  h                      h                   h
      
                          f(x+3h) - 3 f(x+2h) + 3 f(x+h) - f(x)
                      =  ---------------------------------------
                                             3
                                            h
      
    2.                     f(x+h) - f(x-h)
         delta f(x,h) =  -----------------
                                2 h
      
      
                          f(x+2h) - f(x)       f(x) - f(x-2h)
                         ----------------  -  ----------------
              2                  2 h               2 h
         delta f(x,h) =  -------------------------------------
                                          2 h
      
                          f(x+2h) - 2 f(x) + f(x-2h)
                      =  ----------------------------
                                        2
                                     4 h
      
      
              3           f(x+3h) - f(x+h)       f(x+h) - f(x-h)     f(x-h) - f(x-3h)
         delta f(x,h) =  ------------------ - 2 ----------------- + ------------------
                                    3                     3                   3
                                 8 h                   8 h                 8 h
      
                          f(x+3h) - 3 f(x+h) + 3 f(x-h) - f(x-3h)
                      =  -----------------------------------------
                                               3
                                            8 h
      

    1. Derive the formulas for Richardson extrapolation to compute the first derivative of f(x) with forward differences.

    2. Derive the formulas for Richardson extrapolation to compute the first derivative of f(x) with central differences.

    Write pseudo-code for Richardson extrapolation to compute a table with n rows using one of the formulas you derived above.

    Answers:

    1. For 0 < r < 1, we expand the forward difference formula as a power series in h:
                                           2 
          Delta f(x,h)  = f'(x) + C h + C h + ...
                                   1     2
      
                                            2 2 
          Delta f(x,rh) = f'(x) + C rh + C r h + ...
                                   1      2
      
      for some constant C and C . 
                         1     2
      To eliminate the first-order term, we multiply the first formula by r
      and subtract from it the second formula:
      
          Delta f(x,h)*r - Delta f(x,rh)                2
         -------------------------------- = f'(x) + C' h + ...
                       r - 1                         2
      
      for some constant C'.
                         2
      
      To obtain higher-order approximations by extrapolation, we need
      Delta f(x,r^i h) and use r^i instead of r in the formula to obtain
      an approximation of order i+1.
      

      Pseudo-code for the algorithm is:

           Input:  D[i][0] = Delta f(x,r^i*h), for i=0,1,..,n.
           Output: D[i][j] contains extrapolated values, j <= i.
      
           for i from 1 to n do
              for j from 1 to i do
                                         i
                            D[i-1][j-1]*r  - D[i][j-1]
                 D[i][j] = ----------------------------
                                         i
                                        r  - 1
      

    2. For 0 < r < 1, we expand the forward difference formula as a power series in h:
                                     2     4
          delta f(x,h)  = f'(x) + C h + C h + ...
                                   1     2
      
                                     2 2     4 4
          delta f(x,rh) = f'(x) + C r h + C r h + ...
                                   1       2
      
      for some constant C and C .
                         1     2
      To eliminate the first-order term, we multiply the first formula by r^2
      and subtract from it the second formula:
      
                        2
          delta f(x,h)*r - delta f(x,rh)                4
         -------------------------------- = f'(x) + C' h + ...
                        2                            2
                       r - 1 
      
      for some constant C'.
                         2
      
      To obtain higher-order approximations by extrapolation, we need
      delta f(x,r^(2*i) h) and use r^(2*i) instead of r^2 in the formula
      to obtain an approximation of order 2*(i+1).
      

      Pseudo-code for the algorithm is:

           Input:  d[i][0] = delta f(x,r^i*h), for i=0,1,..,n.
           Output: d[i][j] contains extrapolated values, j <= i.
      
           for i from 1 to n do
              for j from 1 to i do
                                         2*i
                            d[i-1][j-1]*r    - d[i][j-1]
                 d[i][j] = ------------------------------
                                         2*i
                                        r    - 1
      

  5. Consider
                    1
                    /  x
               I = |  e  dx
                   /
                    0
    
    Write your answers to the questions below with six decimal places.

    1. Apply the composite trapezoidal rule with 4 subintervals to approximate I.

    2. Apply Romberg integration to obtain a sixth-order approximation of I.

    3. How many decimal places are correct in the final answer from Romberg integration? Explain.

    Answers:

    1. With 4 subintervals, h = 1/4 and we compute:
                 ( 1 )    1 (  0    1 )    1 (  1/4    1/2    1/4 )
         T(h) = T(---) = ---( e  + e  ) + ---( e    + e    + e    )
                 ( 4 )    8 (         )    4 (                    )
      
              = 1.72722
      

    2. Recall that the composite trapezoidal rule is already a second-order approximation for the integral. To obtain a fourth-order approximation we extrapolate once, and for a sixth-order approximation we have to extrapolate twice.

      First we compute T(1/8) and T(1/16):

          ( 1 )    1  (  0    1 )    1 (  1/8   1/4   3/8   1/2   5/8   3/4   7/8 )
         T(---) = ----( e  + e  ) + ---( e   + e   + e   + e   + e   + e   + e    )
          ( 8 )    16 (         )    8 (                                          )
      
                   1   ( 1 )     1 (  1/8   3/8   5/8   7/8 )
                = --- T(---)  + ---( e   + e   + e   + e    )
                   2   ( 8 )     8 (                        )
      
                = 1.72052
      
      The relation between two consecutive applications of the composite trapezoidal rule is especially handy as we get to the next stage:
          ( 1  )    1   ( 1 )    1  (  1/16   3/16   5/16    7/16   9/16
         T(----) = --- T(---) + ----( e    + e    + e    + e     + e 
          ( 16 )    2   ( 8 )    16 (                                
      
                                              11/16   13/16   15/16 )
                                           + e     + e     + e      )
                                                                    )
                 = 1.71884
      
      Now we are ready to extrapolate:
         1.72722
      
                    1.72052*4 - 1.72722
         1.72052   --------------------- = 1.71829
                            4 - 1
      
                    1.71884*4 - 1.72052               1.71828*16 - 1.71829
         1.71884   --------------------- = 1.71828   ---------------------- = 1.71828
                            4 - 1                             16 - 1
      

    3. How many decimal places are correct? Just by eyeballing the results of the extrapolation table we could say that at least six decimal places are correct, as the numbers in the last row, in the last two columns are equal in the first six decimal places.

      Theoretically we have a sixth-order approximation, which means that the error is of order O(h^6). With h = 1/16, we compute (1/16)^6, or about 6*10^(-8), which means that we have about seven significant digits correct.

  6. The midpoint rule for
                 b
                 /                        ( a+b )
                |  f(x) dx    is  (b-a) f (-----)
                /                         (  2  )
                 a
    
    
    Give the formula for the composite midpoint rule that applies the midpoint rule to n equally sized subintervals of [a,b].

    Answer:

               n
              ---   (     (     1  )    )              b - a
            h >    f( a + (i + --- )  h )   for   h = -------
              ---   (     (     2  )    )                n
              i=1
    

  7. Simpson's rule on an interval [a,b] approximates
           b
           /           b-a 
           | f(x) dx = --- ( f(a) + 4*f((a+b)/2) + f(b) )
           /            6 
           a
    
    1. Write a composite formula to integrate f(x) over [a,b], with Simpson's rule, using seven function evaluations.

      Answer:

      Simpson's rule uses 3 function evaluations per interval, but when dividing the interval [a,b] into subintervals, the function evaluation at the interior boundaries of the subintervals are shared. Therefore, if we subdivide [a,b] in 3 subintervals, we will use seven function evaluations.

      The formula is

           b-a (                                
           ---*( f(x(0))+4*f(x(1))+2*f(x(2))+4*f(x(3))
            18 (                            
      
                                             )
                +2*f(x(4))+4*f(x(5))+f(x(6)) )
                                             )
      
      with
             x(k) = a + k*(b-a)/6, k = 0,1,..,6
      
    2. Give the formula for the general composite Simpson's rule, over n subintervals of [a,b], of length (b-a)/n.

  8. Consider the approximation of
                 3a
                 /   
                |   f(x) dx
                /
                 a 
    
    by the rule w_1 f(a) + w_2 f(2a) + w_3 f(3a).

    1. Determine the weights w_1, w_2, and w_3 so that the rule has the highest possible algebraic degree of precision.

    2. Can we reach a higher algebraic degree of precision to approximate the integral? Explain how. What is the highest possible algebraic degree of precision we can reach with three function evaluations?

    Answers:

    1. We want the equality
                   3a
                   /
                  |   f(x) dx = w f(a) + w f(2a) + w f(3a)
                  /              1        2         3
                   a
      
                                 2
      to hold for f = 1, x, and x .  Therefore, we solve the system
      
                   3a
                   /
                  |   1 dx =    2 a  = w  + w + w 
                  /                     1    2   3
                   a
      
                   3a
                   /              2
                  |   x dx =   4 a   = w a + w  2 a + w  3 a
                  /                     1     2        3
                   a
      
                   3a
                   /   2      26   3      2        2        2
                  |   x dx = ---- a  = w a + w  4 a + w  9 a
                  /            3        1     2        3
                   a
      
      where a is a parameter.  The solution to the linear system is
      
               1              4             1
         w  = --- a     w  = --- a    w  = --- a
          1    3         2    3        3    3
      
      

    2. We can increase the algebraic degree of precision if we evaluate the function at points other than a, 2a, and 3a.

      The highest algebraic degree of precision we can reach with Gaussian quadrature using three function evaluations is 5 = 2*3 - 1.

Please note the policy on skipping exams:

If an exam is missed, then greater weight will be placed on the final exam, especially on the material covered on the missing exam.

What this means is that if you decide not to take one midterm exam, your final exam will be weighted for one hundred points more.

What it does NOT mean is that you can drop the score of a midterm exam. If you take the midterm, then your score counts. So, please be prepared when you show up for the exam.