Lab. Study: Preliminaries

Numbers are represented in binaries, thus creating errors.
Numerical procedures also introduce errors.
Numerical analysis is the study of the behaviour of errors in computation.
  1. Write the following code and study the response.

    \includegraphics[scale=1]{figures/0-36}
  2. Write the following code and study the response (http://siber.cankaya.edu.tr/ozdogan/NumericalComputations//mfiles/chapter0/chop.m chop.m).

    \includegraphics[scale=1]{figures/0-37}
  3. Write a code that adds 0.0001 one thousand times. The result should equal 1.0 exactly but this is not true for single precision.

    \includegraphics[scale=1]{figures/0-39}

    Example output;
    k =
      1.0000e+00
    a =
      1.0001e+00
    
  4. Write the following code and study the response.

    \includegraphics[scale=1]{figures/0-38}
  5. Taylor Series Approximations to $ 1/(1-x)$ (Example m-file: http://siber.cankaya.edu.tr/ozdogan/NumericalComputations//mfiles/chapter0/demoTaylor.m demoTaylor.m)
    Consider the function

    $\displaystyle f(x)=\frac{1}{1-x}
$

    Make the Taylor series expansion of this function up to third order.
    >>demoTaylor(1.6,0.8)
    
    All of the Taylor polynomials agree with $ f(x)$ near $ x_0=1.6$. The higher order polynomials agree over a larger range of $ x$.
Home Study:
  1. Suppose that $ \widehat{p}$ is an approximation to $ p$. The (absolute) error is $ E_p = \vert p - \widehat{p}\vert$, and the relative error is $ R_p = \frac{E_p}{\vert p\vert}$, provided that $ p\neq 0$.
  2. Given that

    $\displaystyle p = \int_0 ^{1/2}e^{x^2}dx = 0.544987104184
$

    It is approximated by using Taylor series as

    $\displaystyle \widehat{p} = \int_0^{1/2}P_8(x)dx = \left[x+ \frac{x^3}{3}+\frac{x^5}{5(2)!}+\frac{x^7}{7(3)!}+\frac{x^9}{9(4)!}\right]_0^{1/2}
= 0.544986720817
$

  3. Calculate $ f(500)$ and $ g(500)$ using 6 digits and rounding, with

    $\displaystyle f(x) = x(\sqrt{x+1} - \sqrt{x}) ,  g(x) = \frac{x}{\sqrt{x+1}+\sqrt{x}}
$

    Solution:
    We have

    $\displaystyle f(500)= 500(\sqrt{501} - \sqrt{500})= 500(22.3830 - 22.3607)= 500(0.0223) = 11.1500
$

    $\displaystyle g(500) =\frac{500}{\sqrt{501}+\sqrt{500}}=\frac{500}{22.3830+22.3607}=\frac{500}{44.7437}
= 11.1748
$

    Note that $ g(x)$ is algebraically equivalent to $ f(x)$, but $ g(500) = 11.1748$ is more accurate than $ f(500)$ to the true answer $ 11.174755300747198\ldots$ to six digits.
  4. Let $ P(x) = x^3-3x^2+3x-1$ , $ Q(x) = ((x-3)x+3)x-1$. Use 3-digit rounding arithmetic to compute $ P(2.19) = Q(2.19) = 1.685159$: Solution:

    $\displaystyle P(2.19)\approx 2.19^3 - 3(2.19)^2 +3(2.19) - 1
= 10.5 - 14.4+6.57 - 1 = 1.67
$

    $\displaystyle Q(2.19)\approx((2.19 - 3)2.19+3)2.19 - 1 = 1.69
$

    The errors are 0.015159 and -0.004841, respectively. Thus the approximation $ Q(2.19)\approx 1.69$ has less error.
  5. Consider the Taylor polynomial expansions

    $\displaystyle e^h = 1+h+\frac{h^2}{2!} + \frac{h^3}{3!} +O(h^4)
$

    $\displaystyle cos h = 1 -\frac{h^2}{2!} +\frac{h^4}{4!}+O(h^6)
$

    What is the order of error term for summation, subtraction and multiplication?
    Solution:
    With $ O(h^4)+O(h^6) = O(h^4) = O(h^4)+\frac{h^4 }{4!}$, we have the sum

    $\displaystyle e^h +cos h = 2+h+ \frac{h^3}{3!}+\frac{h^4}{4!}+O(h^4)+O(h^6)= 2+h+\frac{h^3}{3!}+O(h^4)
$

    The difference behaves similarly.
    The product

    $\displaystyle e^h * cos h = \left( 1+h+\frac{h^2}{2!} + \frac{h^3}{3!} +O(h^4)\right)*\left( 1 -\frac{h^2}{2!} +\frac{h^4}{4!}+O(h^6)\right)
$

    $\displaystyle =\left(1+h+\frac{h^2}{2!} + \frac{h^3}{3!}\right)*\left(1 -\frac{...
...\frac{h^4}{4!}\right)+\left(1+h+\frac{h^2}{2!} + \frac{h^3}{3!}\right)*O(h^6)+
$

    $\displaystyle \left(1 -\frac{h^2}{2!} +\frac{h^4}{4!}\right)*O(h^4)+O(h^4)*O(h^6)
$

    $\displaystyle = 1+h -\frac{h^3}{3}-\frac{5h^4}{24}-\frac{h^5}{24}+\frac{h^6}{48}+\frac{h^7}{144}
+O(h^6)+O(h^4)+O(h^4)O(h^6)
$

    $\displaystyle = 1+h -\frac{h^3}{3}+O(h^4)
$

    and the order of approximation is $ O(h^4)$.

Cem Ozdogan 2011-12-27