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.
#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(); }
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.