Homework assignments for Math 304

Zhonggang Zeng

June 19, Thursday, Homework 01
(Due Tuesday, June 24)
    Problems #1, 2, 3, 4 at the end of 
         A simple introduction to numerical programming with Maple
     (This is a mws file, which can be read by Maple only. Save the file
      as a:mplintro.mws, open Maple V.4, and open a:mplintro.mws inside
      Maple)
     Note: if you choose to take "C-only option", you need to have my 
     permission and skip this assignment.
June 24, Tuesday, Homework 02
(Due Thursday, June 26)
     Problem #1: Write the correct program to solve the quadratic equation
                        a*x^2 + b*x + c = 0
                 and test your program for the following equations
                        (10^(-15))*x^2+x+1 = 0
                        (10^(-15))*x^2-x+1 = 0
     Problem #2: The following two functions are equal mathematically:
                     f(x) = ( sqrt(1+x)-1) / x
                     g(x) = 1 /( sqrt(1+x)+1 )
                 Write a program to calculate the two equivalent functions
                 for i = 0.1, 0.01, 0.001, ..., 10^(-n), for n up to 12
                 and compare the behavior of their numerical calculation.
     Problem #3: The following functions contain subtractions of close
                 numbers and result in inaccurate numerical calculation. 
                 Manipulate the functions and propose equivalent ways of 
                 calculation without subtraction:
                  (i) x^2 / ( 1-cos(x) )     for small x
                  (ii)  x * ( sqrt(1+x^2)-x )  for large x
                  (iii) ln(1+x)-ln(x)          for large x
June 26, Thursday, Homework 03
Problem #1: Write a bisection program to solve the
equation
                x^2-3 = 0
Problem #2: Mary can afford $250/month contributed to her
401(k). She plans to work for 30 years and retire a 
millionair. What annual return should she look for? Use 
bisection method (program) to solve the problem.
Problem #3: Given
 x(t) = (g/(2*w^2))*( (exp(w*t)-exp(-w*t))/2 - sin(w*t))
and data
      t = 1
      x(1) = 1.7
      g = -32.17 
use bisection program to solve for w, which is negative.
July 1, Tuesday Homework 04
Write a Newton's iteration program and a secant method 
to find all solutions the following equations
  (1) sin(x)-exp(-x) = 0 in [0,4] to 10^(-5)
  (2) 4*x*cos(2*x) - (x-2)^2 = 0  in [0,8] to 10^(-5)
  (3) 0.5+0.25*x^2-x*sin(x)-0.5*cos(2*x) = 0
       in [0,Pi] to 10^(-5)
Test Newton's iteration on (1), (2), and (3)
Test Secant methd on (1) and (2)
Compare bisection methed, secant method and Newton's 
iteration on (1) with epsilon = 10^(-8)
July 3, 1997 Thursday
   Homework 05: Investigate 
      (1) existance
      (2) uniqueness
      (3) obtainability
      (4) speed to accuracy 10^(-5)
   of the following fixed point problems
      (i) x = (2-exp(x)+x^2)/3
      (ii) x = sqrt(exp(x)/3)
July 8, 1997, Tuesday
   Homework 06: 
      #1: Investigate the convergence rate of the 
          following fixed point iterations solving
                  x^5 = 7
          and rank them in the order from the fastest
          to the slowest:
          (1) x[n] = sqrt( 1 + (7-x[n-1]^3)/x[n-1]^2 )
          (2) x[n]=x[n-1]-(x[n-1]^5-7)/x[n-1]^2
          (3) x[n]=x[n-1]-(x[n-1]^5-7)/(5*x[n-1]^4)
          (4) x[n]=x[n-1]-(x[n-1]^5-7)/12

      #2: From the given data:
              x       2.9      3.0      3.1    3.2
             f(x)   -4.83    -4.24    -3.50  -2.57
          estimate f(Pi)

      #3: From the given data:
             x      1.0    1.1    1.2   1.3    1.4
            f(x)   1.68   1.95   2.20  2.44   2.67
          estimate f(1.15)

      #4: Write down the Lagrange interpolation 
          polynomial in the unsimplified form using
          the data from #3
July 11, Thursday
    Homework 07
      #1 Write a Maple program for Lagrange interpolating polynomial 
        Input
            n    ---  the degree of the polynomial
            u    ---  array(0..n) containing nodes on x-axis
            v    ---  array(0..n) function values on nodes
            x    ---  variable for the polynomial
         output
            the value of the polynomial at x

       #2 Determine a polynomial to fit the following data
           x     1.2      1.3      1.4      1.5
          f(x)   2.57     3.60     5.79    14.1
          f'(x)  7.62    13.98    34.62
        and use the polynomial to check a few values compared 
        with the original function tan(x)

        #3 For the given data
               x    3.0     3.1     3.2
              f(x)  -4.24   -3.497  -2.597
          (1) (pencil work) define the natural cubic spline and 
               write down the necessary equations used to determine
               the coeficients in the piecewise polynomial
          (2) Use Maple to determine the cubic spline and check accuracy
              against the original function
                      f(x) = x*cos(x)-x^2*sin(x)
July 15, 1997
    Homework 08
      #1. For the functions x*ln(x) and exp(x) on the interval [8,8.7] with
          nodes 8.0, 8.1, 8.3, 8.6 and 8.7,
        (i) investigate the theoretical error bound of the the Lagrange
            interpolation polynomial to the function;
        (ii) investigate the actual error bound.
      #2. For data
       x | 0.9 1.3 1.9  2.1  2.6  3.0  3.9 4.4   4.7   5.0  6.0  7.0  8.0  9.2  10.5 11.3 11.6 12.0 12.6 13.0 13.3
          f(x)| 1.3 1.5 1.85 2.1  2.6  2.7  2.4  2.15  2.05  2.1  2.25 2.3  2.25 1.95 1.4  0.9  0.7  0.6  0.5  0.4  0.25
      Plot the Lagrange interpolation polynomial. The data is the top profile
      of a flying duck. Use the graph to demonstrate the shortcomings of the
      Lagrange interpolation with large amount of data
July 17, 1997
    Homework 09
      #1. Propose a quadratic spline function that approximates a function via
          fitting data
            (x0,f(x0)), (x1,f(x1)), ..., (xn,f(xn))

      #2. Use the program ntrlspln.txt and your cubic spline evaluation 
          to plot data in Problem #2, Homework 08.

      #3. For a function f(x) = x - (ln(x))^x and nodes
                x = 3.6, 3.8, 4.0, 4.2
        visually investigate the actually error function on [3.6,4.2] of
           (i) the Lagrange interpolation 
           (ii) the cubic spline
           (iii) the quadratic spline you proposed in Problem #1. (Hint: use
                 Maple "solve" to compute parameters of the quadratic spline
                 and use "piecewise" to define it, then plot)
July 22, 1997
  Homework 10 
    #1: For data
        x      1.1    1.2    1.3    1.4
       f(x)    1.95   2.20   2.44   2.67
    (1) Derive a four point formula for approximating
           (i) f'(1.1)  and  f'(1.4)
           (ii) f''(1.1)
    (2) carry out the approximation using your formulas and
        check with f(x) = ln(exp(2*x)-2) for actual errors.

    #2: For data
         x    0.2    0.4    0.6     0.8    1.0
        f(x)  0.98   0.918  0.808   0.639  0.384
     (1) Derive a five point formula for approximating
               f'(0.4)  and  f'(0.8)
     (2) carry out the approximation using your formula

    #3: Write a Maple program for input
            n, f, a, b
      calculate the numerical integration of f(x) over 
      interval [a,b], that is divided into n subintervals.
July 24, 1997
   Homework 11
     #1 Find a formula to approximate f'(x0) with 
          a*f(x0-h)+b*f(x0)+c*f(x0+s)+d*f'(x0-h)+e*f'(x+s)
      and use your formula to approximate f'(3.05) with
        x0-h=2.91,  x0=3.05, x0+s=3.23
      and f(x) = x*ln(x). Check actual accuracy
     
     #2. Find a, b, c, d such that 
          a*f(x0)+b*f(x1)+c*f(x2)+d*f(x3)
       approximate the definite integral of f(x) over [x0,x3], where
          x1=x0+h, x2=x1+h, x3=x2+h
     #3. Write a program for input n, f, a, b, output the approximate
       definite integral of f(x) on [a,b] using the simpson's rule
       on 2*n subintervals.
     #4. Write a backward substitution program that solves an upper-
       triangular linear system. Test your program for the system
          | 2   3   -1  -6 | |x1|     |-2|
          | 0   5    3  -4 | |x2|  =  | 4|
          | 0   0   -3   7 | |x3|     | 4|
          | 0   0    0   4 | |x4|     | 4| 
July 29, 1977
   Homework #12
     #1 Program the straightforward Gaussian elimination program
     #2 Program the Gaussian elimination with pivoting
   Test the above two programs on
     (1)    0.000001 x1 + x2  = 1.000001
                     x1 + x2  = 2
         with Digits:=5;
     (2) | Pi    -exp(1)   sqrt(2) -sqrt(3) | | x1 |   |sqrt(11)|
         | Pi^2   exp(1)   -exp(2)    3/7   | | x2 |   |  0     |
         |sqrt(5) -sqrt(6)    1    -sqrt(2) | | x3 | = |  Pi    |
         | Pi^3   exp(2)   -sqrt(7)  1/9    | | x4 |   |sqrt(2) |
         with Digits:=3; and Digits:=10
     #3 How many multiplication is needed for straightforward
        Gaussian elimination?  (pencil work)
July 31, 1997
   Homework #13
      #1 Estimate the relative error of the linear system
               x+2y+3z = 10
              2x+3y+4z = -10
               x+4y+6z = 20
         if the right-hand side entries have a plus or minus 0.01
         absolute error.
   
      #2 Program the Jacobi iterative method and test 
              3x -  y +  z = 1
              3x + 6y + 2z = 0
              3x + 3y + 7z = 4
        with tolerance 0.00001
July 5, 1997
   Homework 14
      #1 For iterative method x = Bx + c, prove that the relative error 
         of x^(k) is less than or equals to ||B||^k:
               ||x^(k) - x^* ||/||x^*|| =< ||B||^k
         if the iteration starts from the zero vector
      #2 For the linear system 
             10w +   x - 2y         =  6
               w + 10x -  y  + 3z   = 25
             -2w -   x + 8y  -  z   = -11
                    3x -  y  + 5z   = -11
         construct matrix B and vector c such that the system is 
         equivalent to x = Bx + c. You need to construct two sets of
         (B,c) using Jacobi and Gauss-Seidel methods.
      #3 Estimate the number of iteration needed for solving the above
         linear system to the RELATIVE error 10^(-5) using (i) Jacobi, 
         (ii) Gauss-Seidel.