Robotics Library  0.7.0
NestedFunction.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2009, Andre Gaschler, Markus Rickert
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 //
14 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 // POSSIBILITY OF SUCH DAMAGE.
25 //
26 
27 #ifndef RL_MATH_NESTEDFUNCTION_H
28 #define RL_MATH_NESTEDFUNCTION_H
29 
30 #include <stdexcept>
31 
32 #include "Function.h"
33 
34 namespace rl
35 {
36  namespace math
37  {
38  template<typename T2, typename T>
39  class NestedFunction : public Function<T>
40  {
41  public:
43  Function<T>(),
44  inner(inner),
45  outer(outer)
46  {
47  this->lower() = this->inner.lower();
48  this->upper() = this->inner.upper();
49  }
50 
51  virtual ~NestedFunction()
52  {
53  }
54 
56  {
57  return new NestedFunction(*this);
58  }
59 
60  T operator()(const Real& x, const ::std::size_t& derivative = 0) const
61  {
62  switch (derivative)
63  {
64  case 0:
65  return this->outer(this->inner(x));
66  break;
67  case 1:
68  return this->outer(this->inner(x), 1) * this->inner(x, 1);
69  break;
70  default:
71  throw ::std::runtime_error("rl::math::NestedFunction: Derivatives > 1 not supported");
72  break;
73  }
74  }
75 
76  protected:
77 
78  private:
80 
82  };
83  }
84 }
85 
86 #endif // RL_MATH_NESTEDFUNCTION_H
rl::math::NestedFunction::outer
const Function< T > & outer
Definition: NestedFunction.h:81
rl::math::Function
A mathematical mapping from Real -> ArrayX.
Definition: Function.h:45
rl::math::NestedFunction::~NestedFunction
virtual ~NestedFunction()
Definition: NestedFunction.h:51
rl::math::Function::upper
Real & upper()
Definition: Function.h:74
rl::math::NestedFunction
Definition: NestedFunction.h:40
rl::math::NestedFunction::inner
const Function< T2 > & inner
Definition: NestedFunction.h:79
rl::math::NestedFunction::operator()
T operator()(const Real &x, const ::std::size_t &derivative=0) const
Evaluates the function or a derivative thereof for a given value x.
Definition: NestedFunction.h:60
rl::math::NestedFunction::NestedFunction
NestedFunction(const Function< T2 > &inner, const Function< T > &outer)
Definition: NestedFunction.h:42
rl::math::NestedFunction::clone
NestedFunction * clone() const
Definition: NestedFunction.h:55
rl::math::Function::lower
Real & lower()
Definition: Function.h:64
rl::math::Real
double Real
Definition: Real.h:42
Function.h
rl
Robotics Library.
Definition: AnalogInput.cpp:30