Contents

  1. Rationale
  2. Example
  3. Extensions
  4. References

Rationale

Derivatives of function are one of most important concepts in modern analysis. However, to calculate derivatives of function in C++ one has to choose one of the follwing approaches:

This library provides a numeric type, the diff_ari type, that calculates the value and the derivative of a function at that value.

The diff_ari class is implemented as a template, in a similar manner to the standard complex class.

Example

Using the diff_ari type, a simple newton iteration can be implemented in the following way:

#include 
#include 
#include "diff_ari.h"

template
T newton( diff (*f)(const diff&) , T x0, const double eps)
{
  int i=0;
  diff y;
  diff x;

  x.d1() = 1.;
  do
  {
    x.d0() = x0;
    y   = f(x);
    x0  = x.d0() - y.d0()/y.d1();

        std::cerr << "f["<< i <<"]( " << x << ") = " << y << std::endl;
  } while((fabs(x.d0()-x0) > eps) && ( (++i) < 5000));

  return x.d0();
}

Extensions

diff_ari provides a first step for a more comprehensive library including the following features:

References

I learned the idea of using this kind of differentiation arithmetics in a lecture on Pascal XSC at the university of Karlsruhe many years ago.

Revised February 12, 2002

© Copyright Peter Schmitteckert 2001-2002. Permission to copy, use, modify, sell and distribute this document is granted provided this copyright notice appears in all copies. This document is provided "as is" without express or implied warranty, and with no claim as to its suitability for any purpose.