Prev Next ExampleFun

Evaluate an Example Function and Its Derivatives
Syntax Type ExampleFun<Type>(const Type &x)
double ExampleFun_x(const double &x)
double ExampleFun_xx(const double &x)

ExampleFun
The function ExampleFun<Type> returns a value @[@ 1 + x + x^2 + x^3 + x^4 @]@

Type
This type must support the * and + operations.

x
the argument value to the function.

ExampleFun_x
returns the derivative of ExampleFun; i.e., @[@ 1 + 2 x + 3 x^2 + 4 x^3 @]@

ExampleFun_xx
returns the second derivative of ExampleFun; i.e., @[@ 2 + 6 x + 12 x^2 @]@

Source Code
 
     template <typename Type>
     inline Type ExampleFun(const Type &x)
     {    Type one = Type(1.);
          Type f   = one + x * (one + x * (one + x * (one + x ) ) );
          return f;
     }
     inline double ExampleFun_x(const double &x)
     {    double f_x  = 1. + x * (2. + x * (3. + x * 4.) );
          return f_x;
     }
     inline double ExampleFun_xx(const double &x)
     {    double f_xx =  2. + x * (6. + x * 12.);
          return f_xx;
     }

Input File: ExampleFun.h