\section{WHY IS NUMERICAL ANALYSIS NECESSARY?} Consider the quadratic equation $x^2 - 80x + 1 = (x-r_1)(x-r_2) = 0$ with roots $$ {80 \pm \sqrt{80^2-4}\over 2}= \cases{\displaystyle 80\left(1-{1\over 80^2}-\cdots\right)\cr \displaystyle {1\over 80}\left(1+{1\over 80^2}+\cdots\right)\cr}\approx \cases{\displaystyle 80.0\cr .0125\cr} $$ to 3 significant digits. Using 3-digit arithmetic, the roots are calculated as $$ \eqalign{ {.800\cdot 10^2 \pm \sqrt{.640\cdot 10^4 - .400\cdot 10^1} \over .200\cdot 10^1} & = {10^2\bigl[.800 \pm \sqrt{.640 - .0004}\,\bigr] \over .200\cdot 10^1}\cr & \rightarrow {10^2\bigl[.800 \pm \sqrt{.640}\,\bigr] \over .200\cdot 10^1}= \cases{\displaystyle 80.0\cr 0.00}.\cr} $$ Note that $ax^2 + bx + c = a(x-r_1)(x-r_2)=ax^2-(r_1+r_2)x+ar_1r_2 \Rightarrow r_2=c/(ar_1).$ Calculating the roots this way gives $r_1=80.0, r_2={1/80.0}=.0125$, perfect! In general, $$ r_1 = {-b -\hbox{sign}(b) \sqrt{b^2-4ac} \over 2a}, \qquad r_2={c\over ar_1}. $$ Consider using 5-digit arithmetic to calculate the dot product of $$ \displaylines{ x= \pmatrix{100.01\cr 102.01\cr .01\cr} \hbox{and\ } y= \pmatrix{1.02\cr -1.00\cr .04\cr}. \cr \matrix{\underline{\hbox{calculated $x_iy_i$}} \cr 102.01\cr -102.01\cr 0.0004\cr} \qquad \matrix{\underline{\hbox{exact $x_iy_i$}} \cr 102.0102\cr -102.01\cr .0004\cr}. \cr} $$ The calculated dot product $$ fl\left(\sum_{i=1}^3 x_iy_i\right)=0.004, $$ whereas the exact $\sum_{i=1}^3 x_iy_i = 0.0006$, a 33\% relative error. A mathematical analysis shows $$ fl\left(\sum_{i=1}^3 x_iy_i\right)= \sum_{i=1}^3 x_iy_i (1+3.03\mu\theta_i), \hbox{ where } \mu=10^{-4},\ |\theta_i| \leq 1. $$ \vfil\eject \noindent {\bf Rules of thumb}: \item{1)} Avoid cancellation error if possible. Examples: $$\displaylines{ \sqrt{x+1} - \sqrt{x} = {1\over\sqrt{x+1} + \sqrt{x}},\cr \sin(x+\epsilon) - \sin x = 2 \cos\left(x+ {\epsilon\over 2}\right) \sin {\epsilon\over 2},\cr \int_n^{n+1} {dx\over 1+x^2} = \tan^{-1} (n+1) - \tan^{-1} n = \tan^{-1} \left({1 \over 1 + n (n+1)}\right), \cr {1\over\sqrt{x}} - {1\over\sqrt{x+1}} = {1\over(x+1)\sqrt{x} + x \sqrt{x+1}}.\cr}$$ \item{2)} Don't add terms with alternating signs or very different magnitudes. e.g., write $$\sum_{k=1}^{100} {(-1)^k\over{k^4}} \qquad \hbox{as} \qquad \sum_{i=50}^1 {(-1)^{2i}\over{(2i)^4}} + \sum_{i=49}^0 {(-1)^{2i+1}\over{(2i+1)^4}}.$$ \item{3)} Write iterative formulas in terms of corrections. e.g., write the iteration $$ x_{n+1} = {x_{n-1} f(x_n) - x_nf(x_{n-1}) \over f(x_n) - f(x_{n-1})} \qquad \hbox{as} \qquad x_{n+1} = x_n - \underbrace{ f(x_n) \left({x_n - x_{n-1} \over f(x_n) - f(x_{n-1})}\right) }_{\hbox{correction to $x_n$}}.$$ \item{4)} Don't divide by small numbers. e.g., $$ {{1 - \cos x\over\sin x}} = \tan{x\over 2}\quad\hbox{for }x\approx0.$$ \vfil\eject