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

    \begin{displaymath}
f(x)=\frac{1}{1-x}
\end{displaymath}

    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

    \begin{displaymath}
p = \int_0 ^{1/2}e^{x^2}dx = 0.544987104184
\end{displaymath}

    It is approximated by using Taylor series as

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

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

    \begin{displaymath}
f(x) = x(\sqrt{x+1} - \sqrt{x}) ,~ g(x) = \frac{x}{\sqrt{x+1}+\sqrt{x}}
\end{displaymath}

    Solution:
    We have

    \begin{displaymath}
f(500)= 500(\sqrt{501} - \sqrt{500})= 500(22.3830 - 22.3607)= 500(0.0223) = 11.1500
\end{displaymath}


    \begin{displaymath}
g(500) =\frac{500}{\sqrt{501}+\sqrt{500}}=\frac{500}{22.3830+22.3607}=\frac{500}{44.7437}
= 11.1748
\end{displaymath}

    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:

    \begin{displaymath}
P(2.19)\approx 2.19^3 - 3(2.19)^2 +3(2.19) - 1
= 10.5 - 14.4+6.57 - 1 = 1.67
\end{displaymath}


    \begin{displaymath}
Q(2.19)\approx((2.19 - 3)2.19+3)2.19 - 1 = 1.69
\end{displaymath}

    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

    \begin{displaymath}
e^h = 1+h+\frac{h^2}{2!} + \frac{h^3}{3!} +O(h^4)
\end{displaymath}


    \begin{displaymath}
cos h = 1 -\frac{h^2}{2!} +\frac{h^4}{4!}+O(h^6)
\end{displaymath}

    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

    \begin{displaymath}
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)
\end{displaymath}

    The difference behaves similarly.
    The product

    \begin{displaymath}
e^h * cos h = \left( 1+h+\frac{h^2}{2!} + \frac{h^3}{3!} +O(...
...\right)*\left( 1 -\frac{h^2}{2!} +\frac{h^4}{4!}+O(h^6)\right)
\end{displaymath}


    \begin{displaymath}
=\left(1+h+\frac{h^2}{2!} + \frac{h^3}{3!}\right)*\left(1 -\...
...ight)+\left(1+h+\frac{h^2}{2!} + \frac{h^3}{3!}\right)*O(h^6)+
\end{displaymath}


    \begin{displaymath}
\left(1 -\frac{h^2}{2!} +\frac{h^4}{4!}\right)*O(h^4)+O(h^4)*O(h^6)
\end{displaymath}


    \begin{displaymath}
= 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)
\end{displaymath}


    \begin{displaymath}
= 1+h -\frac{h^3}{3}+O(h^4)
\end{displaymath}

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

Cem Ozdogan 2010-10-09