MCS 471 Final Exam of Spring 2002

  1. Consider the representation of floating-point numbers with base 10 and 2 digits in the fraction part. The values for the exponents are between -10 and +10.
    1. What is the machine precision is this number system?
    2. Represent the numbers 319 and 284 as floating-point numbers.
      Illustrate the calculation of 319+284 and 319-284. Use rounding everywhere.

    Answer:

    1. 10^(-2)
    2. 600 and 40:
             319 = +.32 10^3
           + 284 = +.28 10^3
          -------------------
                   +.60 10^3 = 600
      
             319 = +.32 10^3
           - 284 = +.28 10^3
          -------------------
                   +.04 10^3 = +.40 10^2 = 40
      
                                                            +--------+
                                                            |    /15 |
                                                            +--------+
    

  2. What is error propagation? Give an illustration on a method we have seen.

    Answer:

    Error propagation is the accumulation of roundoff error during calculations. For example: deflation in root finding of univariate polynomials. Let a be a root of the polynomial f(x). To find other roots, we continue with g(x) = f(x)/(x-a). Since we have only an approximation for the root and not the exact root, the coefficients of g(x) are approximate. As we continue the deflations, the approximations for the roots will be less and less accurate.

                                                            +--------+
                                                            |    /10 |
                                                            +--------+
    

  3. Consider f(x) = x^2 - 3 x. Apply three steps of the golden section search method to find the minimum of f(x) in the interval [0,1]. Write the values for a, b, x1, x2, f(x1), and f(x2) in the table (4 decimal places):

    Answer:

    +------+----------+----------+----------+----------+-----------+-----------+
    | step |    a     |    b     |    x1    |    x2    |   f(x1)   |   f(x2)   |
    +======+==========+==========+==========+==========+===========+===========+
    |   0  | 0.000E+0 | 1.000E+0 | 3.820E-1 | 6.180E-1 | -1.000E+0 | -1.472E+0 |
    |   1  | 3.820E-1 | 1.000E+0 | 6.180E-1 | 7.639E-1 | -1.472E+0 | -1.708E+0 |
    |   2  | 6.180E-1 | 1.000E+0 | 7.639E-1 | 8.541E-1 | -1.708E+0 | -1.833E+0 |
    +------+----------+----------+----------+----------+-----------+-----------+
    
                                                            +--------+
                                                            |    /15 |
                                                            +--------+
    

  4. Consider the linear system A x = b. The condition number of the matrix A is 10^9. Assuming the relative error on A is of magnitude 10^(-16), and using exact arithmetic, how many decimal places in the answer can we trust? Justify your answer.

    Answer:

    Denote by x the exact and by xx the approximate solution. Let AA be the floating-point representation of the given matrix A. Then the relative error on the solution is bounded as follows:

            || x - xx ||            || A - AA ||
            ------------ <= cond(A) ------------
                ||x||                   ||A||
     
                         <= 10^9  10^(-16) = 10^(-7)
    
    So we can trust seven decimal places in the answer.
                                                            +--------+
                                                            |    /10 |
                                                            +--------+
    

  5. Suppose you are given a nonlinear boundary-value problem. Which method would you choose to solve it: shooting or finite differences? Justify your choice.

    Answer:

    We prefer shooting because the method of finite differences would lead to a large nonlinear system.

                                                            +--------+
                                                            |    /10 |
                                                            +--------+
    

  6. Consider the matrix
              [ -1.000   4.000  -1.000  ]
          A = [  1.000   2.000   4.000  ]
              [  3.000  -3.000   4.000  ]
    
    1. Compute the LU decomposition of A with partial pivoting.

      Calculate with four decimal places, using rounding: write the answer of every step rounded to four decimal places, and use the rounded number in the calculations of the next step.

    2. What is the determinant of A?

    Answer:

    1.           [ -1.000   4.000  -1.000  ] 1
            A = [  1.000   2.000   4.000  ] 2 
                [  3.000  -3.000   4.000  ] 3
      
                [  3.000  -3.000   4.000  ] 3
       ------>  [  1.000   2.000   4.000  ] 2 
                [ -1.000   4.000  -1.000  ] 1
      
       R2 = R2 - 1/3*R1   [  3.000   -3.000   4.000  ] 3
      ------------------> [  0.3333   3.000   2.667  ] 2
       R3 = R3 + 1/3*R1   [ -0.3333   1.000   0.3333 ] 1
      
       R3 = R3 - 1*R2     [  3.000   -3.000   4.000 ] 3
      ------------------> [  0.3333   3.000   2.667 ] 2
                          [ -0.3333   1.000  -2.334 ] 1
      
          [  1.000    0.000   0.000  ]
      L = [  0.3333   1.000   0.000  ]
          [ -0.3333   1.000   1.000  ]
      
          [  3.000   -3.000   4.000 ]        [ 0 0 1 ]
      U = [  0.000    3.000   2.667 ]    P = [ 0 1 0 ]
          [  0.000    0.000  -2.334 ]        [ 1 0 0 ]
      
      
    2. det A = det L det U det P = 1*(-21.006)*(-1) = 21.01
                                                            +--------+
                                                            |    /25 |
                                                            +--------+
    

  7. We sampled a function f at x = 0,1,2,3 and obtained the function values f(0) = -6, f(1) = -5, f(2) = -2, and f(3) = 3. Compute the Newton form of the polynomial which interpolates the data (i,f(i)), i=0,1,2,3.

    Answer:

      0  -6
               -5+6
               ----- = 1
                1-0         2-1
      1  -5                ----- = 1
               -2+6         2-1         1-1
               ----- = 2               ----- = 0
                2-0         3-1         3-2
      2  -2                ----- = 1
                3+6         3-1
               ----- = 3
                3-0
      3   3
    
    
    p(x) = -6 + 1*(x-0) + 1*(x-0)*(x-1) + 0*(x-0)*(x-1)*(x-2)
    
                                                            +--------+
                                                            |    /15 |
                                                            +--------+
    

  8. The Maclaurin expansion of arcsin(x) is
                          1   3    3   5    5   7   35   9    (  10 )
         arcsin(x) = x + --- x  + --- x  + --- x + ---- x  + O( x   )
                          6        40      112     1152       (     )
    
    
    Use this Maclaurin expansion to construct a Padé approximation for arcsin(x) as a quotient of two quadrics.

    Answer:

           a0 + a1*x + a2*x^2
       R = ------------------
            1 + b1*x + b2*x^2
    
      (1+b1*x+b2*x^2)*(x+x^3/6+3*x^5/40) - a0 - a1*x - a2*x^2
    
       0 - a0 = 0        a0 = 0
       1 - a1 = 0        a1 = 1                     x
       b1 - a2 = 0       a2 = 0             R = -----------
       1/6 + b2 = 0      b2 = -1/6               1 - x^2/6
       1/6*b1 = 0        b1 = 0
    
                                                            +--------+
                                                            |    /15 |
                                                            +--------+
    

  9. Consider a function whose values are tabulated below:
         *=======*==============*
         |   x   |    f(x)      |
         *=======*==============*
         | 0.000 | 0.0000000000 |
         | 0.125 | 0.1256551366 | 
         | 0.250 | 0.2553419212 |
         | 0.375 | 0.3936265759 |
         | 0.500 | 0.5463024898 |
         | 0.625 | 0.7214844410 |
         | 0.750 | 0.9315964599 |
         | 0.875 | 1.197421629  |
         | 1.000 | 1.557407725  |
         *=======*==============*
    
    1. Compute the most accurate approximation for f'(0.5).
    2. How many decimal places in your answer are correct? Justify.

    Answer:

    1. We apply Richardson extrapolation with r = 1/2, using central differences:
                 1.557407725 - 0.0000000000
      h=0.5   : --------------------------- = 1.557407725
                            1                             \
                                                            (a)
                0.9315964599 - 0.2553419212               /
      h=0.25  : --------------------------- = 1.352509077
                            0.5                           \
                                                            (b)   
                0.7214844410 - 0.3936265759               /
      h=0.125 : --------------------------- = 1.311431460
                            0.25
      
      
             1.557407725*(1/4) - 1.352509077
       (a) = ------------------------------- = 1.284209528
                         (1/4) - 1                         \
                                                             (c)
             1.352509077*(1/4) - 1.311431460               /
       (b) = ------------------------------- = 1.297738690
                         (1/4) - 1
      
      
             1.284209528*(1/16) - 1.297738690
       (c) = -------------------------------- = 1.298640634
                         (1/16) - 1
      
    2. We obtained a sixth order approximation:
               O(h^6) with h = 0.125, h^6 = 3.8 E-6
      
      So we have about five decimal places right.
                                                            +--------+
                                                            |    /25 |
                                                            +--------+
    

  10. Apply the method of underdetermined coefficients to derive an Adams-Bashforth formula which uses three function evaluations.

    Answer:

    
          x(n+1)   x(n+1)
         /        /
         |        |
         | dy  =  | f(x,y(x))dx = c1 f(n-2) + c2 f(n-1) + c3 f(n)
         |        |
         /        /
          x(n)     x(n)
    
        Without loss of generality, we let x(n) = 0 and x(n+1) = h,
        and require that all quadrics be integrated correctly:
    
                 h
                / 
        f=1  :  | 1 dx =   h   = c1       + c2      + c3
                /
                 0
    
                 h
                /         h^2
        f=x  :  | x dx = ----- = c1*(-2h) + c2*(-h) + c3*0
                /          2
                 0
    
                 h
           2    /  2      h^3            2         2      2
        f=x  :  | x dx = ----- = c1*(-2h) + c2*(-h) + c3*0
                /          3 
                 0
    
        The solution to this system is 
          c1 = 2*h/12, c2 = -16*h/12, c3 = 23*h/12.
    
                                                            +--------+
                                                            |    /15 |
                                                            +--------+
    

  11. Suppose we want to solve the initial-value problem y' = f(x,y), y(0) = 1, with a predictor-corrector method using four points in each step. Calculate how many times we evaluate f to approximate y(0.7), using step size h = 0.1.

    Answer: Since our predictor-corrector method requires four points in each step, we first need three steps with a Runge-Kutta method which uses the same number of function evaluations in each step.

    
          x0     x1     x2    x3    x4    x5    x6    x7
           [------|------|-----|-----|-----|-----|-----|
           0     0.1    0.2   0.3   0.4   0.5   0.6   0.7
    
      method:    RK     RK    RK    P-C   P-C   P-C   P-C
      #evals:     4  +   4  +  4  +  1  +  1  +  1  +  1   =  16
    
    
                                                            +--------+
                                                            |    /15 |
                                                            +--------+
    

  12. Consider the boundary-value problem y" + y = 3 x^2, y(0) = 1, and y'(1) = 0.

    Give the linear system one has to solve in the method of finite differences with h = 0.2. Be considerate for the mixed boundary conditions.

    Answer:

     
       y'(i) = (y(i+1) - 2*y(i) + y(i-1))/h^2, i = 0,1,..,5 = (1-0)/0.2
    
       x(i) = 0 + i*h, h = 0.2
    
       y(i+1) - (2-h^2)*y(i) + y(i-1) = 3*x(i)^2*h^2
    
       boundary conditions:
    
       1)  y(0) = 1 
    
       2)  y'(1) = (y(1+h) - y(1-h))/(2*h) = (y(6) - y(4))/(2*h)
           y'(1) = 0 => y(6) = y(4)
    
       So the linear system we have to solve is
    
    [ -2+h^2   1      0      0      0    ][y(1)]   [ 3 0.2^2 h^2 - 1 ]
    [   1    -2+h^2   1      0      0    ][y(2)]   [ 3 0.4^2 h^2     ]
    [   0      1    -2+h^2   1      0    ][y(3)] = [ 3 0.6^2 h^2     ]
    [   0      0      1    -2+h^2   1    ][y(4)]   [ 3 0.8^2 h^2     ]
    [   0      0      0      2    -2+h^2 ][y(5)]   [ 3       h^2     ]
    
                                                            +--------+
                                                            |    /15 |
                                                            +--------+
    

  13. Consider the boundary-value problem y" + y' = x, with y(0) = 2 and y(1) = 5.

    With our first guess y'(0) = 1 we find 0.735758 at x=1. Our second guess y'(0) = 3 yields 1.47152 at x=1. What is your next guess for y'(0) in the shooting method?

    Answer:

      p(1) = 0.735758
      p(3) = 1.47152
    
              z-1             z-3
      p(z) = ----- 1.47152 + ----- 0.735758
              3-1             1-3
    
           = 0.367881 z + 0.367877
    
      find z so that p(z) = 5
    
           5 - 0.367877
      z = -------------- = 12.5914
             0.367881
    
                                                            +--------+
                                                            |    /15 |
                                                            +--------+