Prev Next CentralStep

A Central Difference Function Object
Syntax CentralStep<FunTypecenStep(
     const 
Fun  &f   , 
     const 
Type &h   )
Type cenStep(const Type &x)

Fun
The object f has type Fun and the syntax
     
f(x)
must return a Type object where the argument x has prototype const Type &x.

Type
The binary operations +, - and / must supported by this type.

Step Size
The argument h specifies the step size for the central difference operation.

Constructor
The constructor syntax
     CentralStep<
FunTypecenStep(fh) creates the function object cenStep from the specified function and step size.

Evaluation
The syntax
     
cenStep(x)
returns the central difference quotient @[@ [ f(x + h) - f(x - h) ] / h @]@ as a Type object.

Source Code
 
     template <typename Fun, typename Type>
     class CentralStep {
     public:
          // constructor
          CentralStep(const Fun &f_, const Type &h_) 
          : f(f_), h(h_)
          { }

          // function object value
          Type operator()(const Type &x) const
          {    return ( f(x + h) - f(x - h) ) / (h + h); }

     private:
          const Fun  f;
          const Type h;
     };

Input File: CentralStep.h