LTI-Lib latest version v1.9 - last update 10 Apr 2010

lti::functionGenerator Class Reference

functionGenerator parses input strings representing mathematical functions of the type $f(x)$ and $f(x,y)$. More...

#include <ltiFunctionGenerator.h>

Inheritance diagram for lti::functionGenerator:
Inheritance graph
[legend]
Collaboration diagram for lti::functionGenerator:
Collaboration graph
[legend]

List of all members.

Classes

class  parameters
 The parameters for the class functionGenerator. More...

Public Member Functions

 functionGenerator ()
 functionGenerator (const parameters &par)
 functionGenerator (const functionGenerator &other)
virtual ~functionGenerator ()
virtual const char * getTypeName () const
virtual bool updateParameters ()
bool apply (const double &x, const double &y, double &result) const
bool apply (const double &x, double &result) const
functionGeneratorcopy (const functionGenerator &other)
functionGeneratoroperator= (const functionGenerator &other)
virtual functorclone () const
const parametersgetParameters () const

Detailed Description

functionGenerator parses input strings representing mathematical functions of the type $f(x)$ and $f(x,y)$.

These strings are converted into a tree structure which allows the retrieval of the functions' result for passed arguments. The calculation is performed in the apply-methods. The string is set in the parameters of this class like in this example:

  #include "ltiFunctionGenerator.h"

  lti::functionGenerator             function;
  lti::functionGenerator::parameters params;
  params.function = "(x-1)*cos(y)/x^2+1.234";
  if (!function.setParameters(params)) {
    // something went wrong during parsing, get the error message
    std::cout << function.getStatusString();
  }
  else {
    // calculate the result for two arguments
    double result;
    if (!function.apply(2.5,3.1,result)) {
      std::cout << "Function is not defined for given arguments";
    }
  }

Conventions for string input:

  1. The string is case insensitive
  2. Numerical constants consists of decimal digits (0-9) and the period (.)
  3. Two numerical constants are defined as literals: 'pi' and 'e'
  4. The names for the variables holding the arguments are 'x' and 'y' by default. These names can be changed in the parameters.
  5. Parenthesis are allowed in any desired depth
  6. Allowed operators: '+','-','*','/','^'
  7. Allowed functions:
    • sin() -> sine
    • cos() -> cosine
    • tan() -> tangent
    • cot() -> cotangent
    • sec() -> secant
    • csc() -> cosecant
    • arcsin() -> arc sine
    • arccos() -> arc cosine
    • arctan() -> arc tangent
    • arccot() -> arc cotangent
    • sinh() -> hyperbolic sine
    • cosh() -> hyperbolic cosine
    • tanh() -> hyperbolic tangent
    • coth() -> hyperbolic cotangent
    • arsinh() -> hyperbolic area sine
    • arcosh() -> hyperbolic area cosine
    • artanh() -> hyperbolic area tangent
    • arcoth() -> hyperbolic area cotangent
    • ln() -> logarithm base e
    • lg() -> logarithm base 10
    • ld() -> logarithm base 2
    • sqrt() -> Square root
    • abs() -> absolute value
    • sgn() -> sign function
    • int() -> greatest integer smaller the argument (Gaussian parenthesis)

Constructor & Destructor Documentation

lti::functionGenerator::functionGenerator (  ) 

Default constructor.

lti::functionGenerator::functionGenerator ( const parameters par  ) 

Construct a functor using the given parameters.

lti::functionGenerator::functionGenerator ( const functionGenerator other  ) 

Copy constructor.

Parameters:
other the object to be copied
virtual lti::functionGenerator::~functionGenerator (  )  [virtual]

Destructor.


Member Function Documentation

bool lti::functionGenerator::apply ( const double &  x,
double &  result 
) const

operates on a copy of the given parameters.

Parameters:
x argument
result result of evaluation. 1.0 in case of errors
Returns:
true if the function is defined for the given argument
bool lti::functionGenerator::apply ( const double &  x,
const double &  y,
double &  result 
) const

operates on a copy of the given parameters.

Parameters:
x first argument
y second argument
result result of evaluation. 1.0 in case of errors
Returns:
true if the function is defined for the given arguments
virtual functor* lti::functionGenerator::clone (  )  const [virtual]

Returns a pointer to a clone of this functor.

Reimplemented from lti::mathFunction.

functionGenerator& lti::functionGenerator::copy ( const functionGenerator other  ) 

Copy data of "other" functor.

Parameters:
other the functor to be copied
Returns:
a reference to this functor object

Reimplemented from lti::mathFunction.

const parameters& lti::functionGenerator::getParameters (  )  const

Returns used parameters.

Reimplemented from lti::mathFunction.

virtual const char* lti::functionGenerator::getTypeName (  )  const [virtual]

Returns the name of this type ("functionGenerator").

Reimplemented from lti::mathFunction.

functionGenerator& lti::functionGenerator::operator= ( const functionGenerator other  ) 

Alias for copy member.

Parameters:
other the functor to be copied
Returns:
a reference to this functor object

Reimplemented from lti::mathFunction.

virtual bool lti::functionGenerator::updateParameters (  )  [virtual]

Updates the internal state after parameter change.

Here, the function string is parsed and the tree is build.

Returns:
true, if the tree was successfully build.

Reimplemented from lti::functor.


The documentation for this class was generated from the following file:

Generated on Sat Apr 10 15:28:20 2010 for LTI-Lib by Doxygen 1.6.1