next up previous
Next: APPENDIX Up: The fussy language: Implementation Previous: Error propagation: Algorithm for

Subsections


Examples

Following are some examples to demonstrate as well as test the correctness of the error propagation algorithm of Section 3. In the following examples, various functions are written in different algebraic forms and the results for the different forms is shown to be exactly same (e.g. $\cos(x)$ vs. $\sqrt{1-\sin^2(x)}$, $\tan(x)$ vs. $\sin(x)/\cos(x)$). These examples also verify that the combination of a function and its inverse simply returns the argument (e.g $asin(\sin(x))=x$), as well as functions like $\sinh(x)/((\exp(x)-\exp(-x))/2)$ (which is really a complicated way of writing $1$!) returns a value of $1$ with no error. However, if the values of two independent variates $x_1$ and $x_2$ and their corresponding errors are same, the value of expressions like $\sin^2(x_1) + \cos^2(x_2)$ will be $1$ but the error will not be zero.
   Value of x         =  1.00000 +/- 0.10000
   Value of y         =  2.00000 +/- 0.20000
   Value of x1        =  1.00000 +/- 0.10000
   Value of x2        =  1.00000 +/- 0.10000

   sin(x)             =  0.84147 +/-  0.05403
   sqrt(1-sin(x)^2)   =  0.54030 +/-  0.08415
   cos(x)             =  0.54030 +/-  0.08415

   tan(x)             =  1.55741 +/-  0.34255
   sin(x)/cos(x)      =  1.55741 +/-  0.34255

   asin(sin(x))       =  1.00000 +/-  0.10000
   asinh(sinh(x))     =  1.00000 +/-  0.10000
   atanh(tanh(x))     =  1.00000 +/-  0.10000
   exp(ln(x))         =  1.00000 +/-  0.10000

   sinh(x)            =  1.17520 +/-  0.15431
   (exp(x)-exp(-x))/2 =  1.17520 +/-  0.15431

   sinh(x)/((exp(x)-exp(-x))/2) =  1.00000
   x/exp(ln(x))                 =  1.00000

   sin(x1)*sin(x1)       =  0.70807 +/- 0.09093
   sin(x1)*sin(x2)       =  0.70807 +/- 0.06430
   sin(x1)^2+cos(x1)^2   =  1.00000 +/- 0.00000
   sin(x1)^2+cos(x2)^2   =  1.00000 +/- 0.12859

Recursion

Following is an example of error propagation in a recursive function. The factorial of $x$ is written as a recursive function $f(x)$. Its derivative is given by $f(x)\left[\frac{1}{x} + \frac{1}{x-1} + \frac{1}{x-2} +\cdots +
\frac{1}{2} + 1\right]$. The term in the parenthesis is also written as a recursive function $df(x)$. It is shown that the propagated error in $f(x)$ is equal to $f(x)df(x)\delta x$.

   >f(x) {if (x==1) return x; else return x*f(--x);}
   >df(x){if (x==1) return x; else return 1/x+df(--x);}
   >f(x=10pm1)
           3628800.00000 +/- 10628640.00000
   >(f(x)*df(x)*x.rms).val
           10628640.00000
Similarly, the recurrence relations for the Laguerre polynomial of order $n$ and its derivative evaluated at $x$ are given by
  $\textstyle L_n(x)$ $\displaystyle = \left\{
\begin{array}{lr}
1&  n=0\\
1-x&  n=1\\
\frac{\left(2n-1-x\right)L_{n-1}(x)-\left(n-1\right)L_{n-2}(x)}{n}&  n\ge2
\end{array}\right.$ (5)
  $\textstyle L^\prime_n(x)$ $\displaystyle = \left(n/x\right)\left[L_n(x) - L_{n-1}(x)\right]$ (6)

These are written as recursive functions l(n,x) and dl(n,x) and it is shown that the propagated error in $L_n(x)$ is equal to $L^\prime_n(x)\delta x$.
   >l(n,x){
      if (n<=0) return 1;
      if (n==1) return 1-x;
      return ((2*n-1-x)*l(n-1,x)-(n-1)*l(n-2,x))/n;
    }
   >dl(n,x){return (n/x)*(l(n,x)-l(n-1,x));}
   >l(4,x=3pm1)
               1.37500 +/-    0.50000
   >(dl(4,x)*x.rms).val
           0.50000


next up previous
Next: APPENDIX Up: The fussy language: Implementation Previous: Error propagation: Algorithm for
Sanjay Bhatnagar 2011-05-28