5 #ifndef BPP_NUMERIC_FUNCTION_OPERATORS_MATHOPERATOR_H 6 #define BPP_NUMERIC_FUNCTION_OPERATORS_MATHOPERATOR_H 33 std::shared_ptr<Operator>
son_;
36 MathOperator(
double (*func)(
double), std::string name, std::shared_ptr<Operator> son) :
37 func_(func), name_(name), son_(son)
53 return (*
func_)(son_->getValue());
55 return son_->getValue();
69 double v = son_->getValue();
70 double d = son_->getFirstOrderDerivative(variable);
74 else if (name_ ==
"log")
77 throw Exception(
"MathOperator::getFirstOrderDerivative : unknown function " + name_);
82 double v = son_->getValue();
83 double d = son_->getFirstOrderDerivative(variable);
84 double d2 = son_->getSecondOrderDerivative(variable);
87 return (d2 + d * d) * exp(v);
88 else if (name_ ==
"log")
89 return (d2 * v - d * d) / (v * v);
91 throw Exception(
"MathOperator::getFirstOrderDerivative : unknown function " + name_);
98 return name_ +
"(" + son_->output() +
")";
102 #endif // BPP_NUMERIC_FUNCTION_OPERATORS_MATHOPERATOR_H
double getFirstOrderDerivative(const std::string &variable) const
1st order derivative
std::string getName() const
double getSecondOrderDerivative(const std::string &variable) const
Implements a unary operator that applies a math (described in cmath) operator.
std::string output() const
MathOperator(double(*func)(double), std::string name, std::shared_ptr< Operator > son)
std::shared_ptr< Operator > getSon()
std::shared_ptr< Operator > son_
Exception base class. Overload exception constructor (to control the exceptions mechanism). Destructor is already virtual (from std::exception)
MathOperator * clone() const
Create a copy of this object and send a pointer to it.
Interface of operator for numerical computation.