1 #ifndef __JTOOLS__JPOLINT__ 
    2 #define __JTOOLS__JPOLINT__ 
   23 namespace JPP { 
using namespace JTOOLS; }
 
   35   template<
unsigned int N, 
 
   37            template<
class, 
class> 
class JCollection_t,
 
   50   template<
unsigned int N, 
class JElement_t, 
template<
class, 
class> 
class JCollection_t, 
class JDistance_t>
 
   56     public JCollection_t<JElement_t, JDistance_t>,
 
   57     public JFunction<typename JElement_t::abscissa_type,
 
   58                      typename JResultType<typename JElement_t::ordinate_type>::result_type>
 
   71     typedef typename collection_type::iterator                                   
iterator;
 
   98         return this->getExceptionHandler().action(
JEmptyCollection(
"JPolintFunction<>::evaluate() no data."));
 
  105       if ((p == this->begin() && this->
getDistance(x, (p++)->getX()) > distance_type::precision) ||
 
  106           (p == this->end()   && this->
getDistance((--p)->getX(), x) > distance_type::precision)) {
 
  107         return this->getExceptionHandler().action(
JValueOutOfRange(
"JPolintFunction::evaluate() x out of range."));
 
  113       const int n = std::min((
int) (N + 1), (
int) this->size());         
 
  115       for (
int i = n/2; i != 0 && p != this->end();   --i, ++p) {}       
 
  116       for (
int i = n  ; i != 0 && p != this->begin(); --i, --p) {}
 
  121       for (
int i = 0; i != n; ++p, ++i) {
 
  127         if (fabs(u[i]) < fabs(u[j])) {
 
  137       for (
int m = 1; m != n; ++m) {
 
  139         for (
int i = 0; i != n-m; ++i) {
 
  141           const double ho = u[ i ];
 
  142           const double hp = u[i+m];
 
  143           const double dx = ho - hp;
 
  170     mutable double      u[N+1];
 
  180   template<
class JElement_t, 
template<
class, 
class> 
class JCollection_t, 
class JDistance_t>
 
  186     public JCollection_t<JElement_t, JDistance_t>,
 
  187     public JFunction<typename JElement_t::abscissa_type,
 
  188                      typename JResultType<typename JElement_t::ordinate_type>::result_type>
 
  201     typedef typename collection_type::iterator                                   
iterator;
 
  228         return this->getExceptionHandler().action(
JEmptyCollection(
"JPolintFunction<>::evaluate() no data."));
 
  235       if ((p == this->begin() && this->
getDistance(x, (p++)->getX()) > distance_type::precision) ||
 
  236           (p == this->end()   && this->
getDistance((--p)->getX(), x) > distance_type::precision)) {
 
  238         return this->getExceptionHandler().action(
JValueOutOfRange(
"JPolintFunction::evaluate() x out of range."));
 
  265   template<
class JElement_t, 
template<
class, 
class> 
class JCollection_t, 
class JDistance_t>
 
  271     public JCollection_t<JElement_t, JDistance_t>,
 
  272     public JFunction<typename JElement_t::abscissa_type,
 
  273                      typename JResultType<typename JElement_t::ordinate_type>::result_type>
 
  286     typedef typename collection_type::iterator                                   
iterator;
 
  313         return this->getExceptionHandler().action(
JEmptyCollection(
"JPolintFunction<>::evaluate() no data."));
 
  320       if ((p == this->begin() && this->
getDistance(x, (p++)->getX()) > distance_type::precision) ||
 
  321           (p == this->end()   && this->
getDistance((--p)->getX(), x) > distance_type::precision)) {
 
  323         return this->getExceptionHandler().action(
JValueOutOfRange(
"JPolintFunction::evaluate() x out of range."));
 
  331       const double dx = this->
getDistance(p->getX(), q->getX());
 
  332       const double a  = this->
getDistance(x, q->getX()) / dx;
 
  333       const double b  = 1.0 - a;
 
  350   template<
unsigned int N, 
class JElement_t, 
template<
class, 
class> 
class JCollection_t, 
class JDistance_t>
 
  356     public JCollection_t<JElement_t, JDistance_t>,
 
  357     public JFunction<typename JElement_t::abscissa_type, 
 
  358                      JResultHesse<typename JResultType<typename JElement_t::ordinate_type>::result_type> >
 
  371     typedef typename collection_type::iterator                                   
iterator;
 
  400         return this->getExceptionHandler().action(
JEmptyCollection(
"JPolintFunction<>::evaluate() no data."));
 
  407       if ((p == this->begin() && this->
getDistance(x, (p++)->getX()) > distance_type::precision) ||
 
  408           (p == this->end()   && this->
getDistance((--p)->getX(), x) > distance_type::precision)) {
 
  410         return this->getExceptionHandler().action(
JValueOutOfRange(
"JPolintFunction::evaluate() x out of range."));
 
  416       const int n = std::min((
int) (N + 1), (
int) this->size());         
 
  418       for (
int i = n/2; i != 0 && p != this->end();   --i, ++p) {}       
 
  419       for (
int i = n  ; i != 0 && p != this->begin(); --i, --p) {}
 
  424       for (
int i = 0; i != n; ++p, ++i) {
 
  432         if (fabs(u[i]) < fabs(u[j])) {
 
  443       for (
int m = 1; m != n; ++m) {
 
  445         for (
int i = 0; i != n-m; ++i) {
 
  447           const double ho = u[ i ];
 
  448           const double hp = u[i+m];
 
  449           const double dx = ho - hp;
 
  451           const data_type r  = (v [i+1] - w [i]) / dx;
 
  452           const data_type rp = (vp[i+1] - wp[i]) / dx;
 
  460         if (2*(j+1) < n - m) {
 
  463           result.fp += vp[j+1];
 
  485     mutable double    u [N+1];
 
  505   template<
unsigned int N, 
class JElement_t, 
template<
class, 
class> 
class JCollection_t, 
class JDistance_t>
 
  511     public JCollection_t<JElement_t, JDistance_t>,
 
  512     public JFunction<typename JElement_t::abscissa_type, 
 
  513                      JResultPDF<typename JResultType<typename JElement_t::ordinate_type>::result_type> >
 
  526     typedef typename collection_type::iterator                                   
iterator;
 
  555         return this->getExceptionHandler().action(
JEmptyCollection(
"JPolintFunction<>::evaluate() no data."));
 
  562       if ((p == this->begin() && this->
getDistance(x, (p++)->getX()) > distance_type::precision) ||
 
  563           (p == this->end()   && this->
getDistance((--p)->getX(), x) > distance_type::precision)) {
 
  565         return this->getExceptionHandler().action(
JValueOutOfRange(
"JPolintFunction::evaluate() x out of range."));
 
  571         const int n = std::min((
int) (N + 1), (
int) this->size());         
 
  573         for (
int i = n/2; i != 0 && p != this->end();   --i, ++p) {}       
 
  574         for (
int i = n  ; i != 0 && p != this->begin(); --i, --p) {}
 
  579         for (
int i = 0; i != n; ++p, ++i) {
 
  586           vi[i] = p->getIntegral();
 
  589           if (fabs(u[i]) < fabs(u[j])) {
 
  598         result.V  = this->rbegin()->getIntegral();
 
  602         for (
int m = 1; m != n; ++m) {
 
  604           for (
int i = 0; i != n-m; ++i) {
 
  606             const double ho = u[ i ];
 
  607             const double hp = u[i+m];
 
  608             const double dx = ho - hp;
 
  610             const data_type r  = (v [i+1] - w [i]) / dx;
 
  611             const data_type rp = (vp[i+1] - wp[i]) / dx;
 
  612             const data_type ri = (vi[i+1] - wi[i]) / dx;
 
  622           if (2*(j+1) < n - m) {
 
  625             result.fp += vp[j+1];
 
  654         this->begin()->setIntegral(V);
 
  656         for (
iterator j = this->begin(), i = j++; j != this->end(); ++i, ++j) {
 
  663             const abscissa_type x = 0.5 * (xmax + xmin  +  m->getX() * (xmax - xmin));
 
  675     mutable double    u [N+1];
 
  690   template<
unsigned int N, 
class JElement_t, 
template<
class, 
class> 
class JCollection_t, 
class JDistance_t>
 
  696     public JCollection_t<JElement_t, JDistance_t>,
 
  697     public JFunction<typename JElement_t::abscissa_type, 
 
  698                      JResultPolynome<N, typename JResultType<typename JElement_t::ordinate_type>::result_type> >
 
  711     typedef typename collection_type::iterator                                   
iterator;
 
  740         return this->getExceptionHandler().action(
JEmptyCollection(
"JPolintFunction<>::evaluate() no data."));
 
  747       if ((p == this->begin() && this->
getDistance(x, (p++)->getX()) > distance_type::precision) ||
 
  748           (p == this->end()   && this->
getDistance((--p)->getX(), x) > distance_type::precision)) {
 
  750         return this->getExceptionHandler().action(
JValueOutOfRange(
"JPolintFunction::evaluate() x out of range."));
 
  756       const int n = std::min((
int) (N + 1), (
int) this->size());         
 
  758       for (
int i = n/2; i != 0 && p != this->end();   --i, ++p) {}       
 
  759       for (
int i = n  ; i != 0 && p != this->begin(); --i, --p) {}
 
  762       for (
unsigned int i = 0; i != N+1; ++i) {
 
  763         for (
unsigned int j = 0; j != N+1; ++j) {
 
  775       for (
int i = 0; i != n; ++p, ++i) {
 
  781         if (fabs(u[i]) < fabs(u[j])) {
 
  786       result.y[0] = v[j][0];
 
  790       for (
int m = 1; m != n; ++m) {
 
  792         for (
int i = 0; i != n-m; ++i) {
 
  794           const double ho = u[ i ];
 
  795           const double hp = u[i+m];
 
  796           const double dx = ho - hp;
 
  798           for (
int k = 0; k != N+1; ++k) {
 
  799             r[k] = (v[i+1][k] - w[i][k]) / dx;
 
  805           for (
int k = 1; k != N+1; ++k) {
 
  806             v[i][k] = ho * r[k]  -  k * r[k-1];
 
  807             w[i][k] = hp * r[k]  -  k * r[k-1];
 
  811         if (2*(j+1) < n - m) {
 
  813           for (
int k = 0; k != N+1; ++k) {
 
  814             result.y[k] += v[j+1][k];
 
  819           for (
int k = 0; k != N+1; ++k) {
 
  820             result.y[k] += w[j][k];
 
  838     mutable double    u[N+1];
 
  852   template<
unsigned int N,
 
  854            template<
class, 
class> 
class JCollection_t,
 
  855            class JResult_t   = 
typename JElement_t::ordinate_type,
 
  858     public JPolintFunction<N, JElement_t, JCollection_t, JResult_t, JDistance_t>,
 
  859     public JFunction1D<typename JElement_t::abscissa_type, JResult_t> 
 
  893   template<
unsigned int N,
 
  896            template<
class, 
class, 
class> 
class JMap_t,
 
  901                            JElement2D<JKey_t, JValue_t>, 
 
  902                            JMapCollection<JMap_t>::template collection_type, 
 
  922     typedef typename JPolintFunction_t::iterator                                 
iterator;
 
  947   template<
unsigned int N,
 
  949            template<
class, 
class> 
class JCollection_t,
 
  952   inline typename JElement_t::ordinate_type
 
  971   template<
unsigned int N,
 
  973            template<
class, 
class> 
class JCollection_t,
 
  976   inline typename JElement_t::ordinate_type
 
  981     typedef typename JElement_t::abscissa_type                                                                abscissa_type;
 
  982     typedef typename JElement_t::ordinate_type                                                                ordinate_type;
 
  987     if (input.getSize() > 1) {
 
  989       output.
put(input.begin()->getX(), V);
 
  993       for (const_iterator j = input.begin(), i = j++; j != input.end(); ++i, ++j) {
 
  995         const abscissa_type xmin = i->getX();
 
  996         const abscissa_type xmax = j->getX();
 
 1000           const abscissa_type x = 0.5 * (xmax + xmin  +  m->getX() * (xmax - xmin));
 
 1001           const ordinate_type v = 0.5 * (xmax - xmin) *  m->getY() * 
get_value(input(x));
 
 1006         output.
put(xmax, V);
 
 1024   template<
class JElement_t,
 
 1025            template<
class, 
class> 
class JCollection_t,
 
 1028   inline typename JElement_t::ordinate_type
 
 1033     typedef typename JElement_t::ordinate_type                                                                ordinate_type;
 
 1038     if (input.getSize() > 1) {
 
 1040       output.
put(input.begin()->getX(), V);
 
 1042       for (const_iterator j = input.begin(), i = j++; j != input.end(); ++i, ++j) {
 
 1044         V += input.getDistance(i->getX(), j->getX()) * j->getY();
 
 1046         output.
put(j->getX(), V);
 
 1064   template<
class JElement_t,
 
 1065            template<
class, 
class> 
class JCollection_t,
 
 1068   inline typename JElement_t::ordinate_type
 
 1073     typedef typename JElement_t::ordinate_type                                                                ordinate_type;
 
 1078     if (input.getSize() > 1) {
 
 1080       output.
put(input.begin()->getX(), V);
 
 1082       for (const_iterator j = input.begin(), i = j++; j != input.end(); ++i, ++j) {
 
 1084         V += 0.5 * input.getDistance(i->getX(), j->getX()) * (i->getY() + j->getY());
 
 1086         output.
put(j->getX(), V);
 
double getValue(const JScale_t scale)
Get numerical value corresponding to scale. 
 
The elements in a collection are sorted according to their abscissa values and a given distance opera...
 
This include file containes various data structures that can be used as specific return types for the...
 
static const JZero zero
Function object to assign zero value. 
 
size_t getSize(T(&array)[N])
Get size of c-array. 
 
double getDistance(const JFirst_t &first, const JSecond_t &second)
Get distance between objects. 
 
Auxiliary template class for type bool. 
 
Exception for numerical precision error. 
 
Auxiliary classes for numerical integration. 
 
Exception for an empty collection. 
 
Exception for accessing a value in a collection that is outside of its range.