Lab 10 (11/10/2017)

Problems and Even More Problems!


  1. Fill the following table using Bisection and Secant methods of root finding. Set error limit as 1e-10 and maximum number of iterations as 1000. Analyse your results.

    FunctionInterval Bisection Method Secant Method
    RootIterations RootIterations
    $x^2 - 9$$[0,5]$
    $x^5 - x - 1$$[1,2]$
    $xe^{-x}$$[-1,2]$
    $2\cos(3x)-e^{x}$$[0,6]$
    $(x-1)^5$$[0,3]$
    $xe^{-x}$$[-1.5,1]$

    In the above table, you can see that the secant method can be either faster or slower than bisection. You may also observe convergence failures: either convergence to a value that is not near a root or convergence to a value substantially less accurate than expected. Regarding the bisection roots as accurate, are there any examples of convergence to a value that is not near a root in the table? If so, which? Are there any examples of inaccurate roots? If so, which?

  2. Approximate the integral of the function $ f(x)=\sqrt{\vert x-0.5\vert}$ over the interval [-1,1] to a tolerance of 1.e-10. The exact value of this integral is $ \sqrt{2}/6+\sqrt{6}/2$. What are the estimated and true errors using all the different methods we learnt in class?
  3. In this problem, we analyse solving systems of equations. Generate coefficient matrix A and the RHS vector b for a given N (the number of variables) using np.random.uniform() function of numpy package. You can also take a look at Lab4 for use of np.random.uniform() function. Then fill the following table and plot N vs. Time. You can get time using the code snippet given after the table.

    Size (N) Time (ms)
    Gauss EliminationGauss Seidel
    100
    200
    300
    400
    500
    1000
    5000
    10000
    20000

In [3]:
import time
import numpy as np

st_time = time.time()
# Put your code here. For example, multiplying two matrices!
A = np.random.uniform(-10., 10., (5000,1000))
B = np.random.uniform(-20., 20., (1000, 700))
C = A.dot(B)
print 'Time taken to multiply A(5000,1000) and B(1000, 700): ', \
    time.time() - st_time, ' s.' 
# When you do your own code, replace the above lines with your code
Time taken to multiply A(5000,1000) and B(1000, 700):  0.34871506691  s.