Jpp
Public Member Functions | Friends | List of all members
JMATH::JPolynome Class Reference

Polynome function object. More...

#include <JPolynome.hh>

Inheritance diagram for JMATH::JPolynome:
std::vector< double >

Public Member Functions

 JPolynome ()
 Default constructor. More...
 
 JPolynome (int n,...)
 Constructor. More...
 
template<class T >
 JPolynome (T __begin, T __end)
 Constructor. More...
 
double getValue (const double x) const
 Function value. More...
 
double getDerivative (const double x) const
 Derivative value. More...
 
double getIntegral (const double x) const
 Integral value. More...
 
double operator() (const double x) const
 Function value. More...
 
JPolynome getDerivative () const
 Derivative function. More...
 
JPolynome getIntegral () const
 Integral function. More...
 
bool equals (const JPolynome &P, const double eps=std::numeric_limits< double >::min()) const
 Equality. More...
 

Friends

std::istream & operator>> (std::istream &in, JPolynome &object)
 Read polynome from input. More...
 
std::ostream & operator<< (std::ostream &out, const JPolynome &object)
 Write polynome to output. More...
 

Detailed Description

Polynome function object.

Evaluates function, derivative and integral values.

Definition at line 26 of file JPolynome.hh.

Constructor & Destructor Documentation

◆ JPolynome() [1/3]

JMATH::JPolynome::JPolynome ( )
inline

Default constructor.

Definition at line 33 of file JPolynome.hh.

34  {}

◆ JPolynome() [2/3]

JMATH::JPolynome::JPolynome ( int  n,
  ... 
)
inline

Constructor.

Parameters
ndegree of polynome (followed by comma separated argument list)

Definition at line 42 of file JPolynome.hh.

43  {
44  va_list ap;
45 
46  va_start(ap, n);
47 
48  for (double x; n != 0; --n) {
49 
50  x = va_arg(ap, double); // next argument
51 
52  push_back(x);
53  }
54 
55  va_end(ap);
56  }

◆ JPolynome() [3/3]

template<class T >
JMATH::JPolynome::JPolynome ( __begin,
__end 
)
inline

Constructor.

Parameters
__beginbegin of data
__endend of data

Definition at line 66 of file JPolynome.hh.

68  {
69  for (T i = __begin; i != __end; ++i)
70  push_back(*i);
71  }

Member Function Documentation

◆ getValue()

double JMATH::JPolynome::getValue ( const double  x) const
inline

Function value.

Parameters
xabscissa value
Returns
function value

Definition at line 80 of file JPolynome.hh.

81  {
82  double y = 0.0;
83  double z = 1.0;
84 
85  for (const_iterator i = begin(); i != end(); ++i, z *= x) {
86  y += (*i) * z;
87  }
88 
89  return y;
90  }

◆ getDerivative() [1/2]

double JMATH::JPolynome::getDerivative ( const double  x) const
inline

Derivative value.

Parameters
xabscissa value
Returns
derivative value

Definition at line 99 of file JPolynome.hh.

100  {
101  double y = 0.0;
102 
103  if (!empty()) {
104 
105  double z = 1.0;
106  int n = 1;
107 
108  for (const_iterator i = begin(); ++i != end(); ++n, z *= x) {
109  y += (*i) * z * n;
110  }
111  }
112 
113  return y;
114  }

◆ getIntegral() [1/2]

double JMATH::JPolynome::getIntegral ( const double  x) const
inline

Integral value.

Parameters
xabscissa value
Returns
integral value

Definition at line 123 of file JPolynome.hh.

124  {
125  double y = 0.0;
126  double z = x;
127  int n = 1;
128 
129  for (const_iterator i = begin(); i != end(); ++i, ++n, z *= x) {
130  y += (*i) * z / n;
131  }
132 
133  return y;
134  }

◆ operator()()

double JMATH::JPolynome::operator() ( const double  x) const
inline

Function value.

Parameters
xabscissa value
Returns
function value

Definition at line 143 of file JPolynome.hh.

144  {
145  return getValue(x);
146  }

◆ getDerivative() [2/2]

JPolynome JMATH::JPolynome::getDerivative ( ) const
inline

Derivative function.

Returns
derivative function

Definition at line 154 of file JPolynome.hh.

155  {
156  JPolynome buffer;
157 
158  int n = 1;
159 
160  for (const_iterator i = begin(); ++i != end(); ++n) {
161  buffer.push_back(n * (*i));
162  }
163 
164  return buffer;
165  }

◆ getIntegral() [2/2]

JPolynome JMATH::JPolynome::getIntegral ( ) const
inline

Integral function.

Returns
integral function

Definition at line 173 of file JPolynome.hh.

174  {
175  JPolynome buffer(1, 0.0);
176 
177  int n = 1;
178 
179  for (const_iterator i = begin(); i != end(); ++i, ++n) {
180  buffer.push_back((*i) / (double) n);
181  }
182 
183  return buffer;
184  }

◆ equals()

bool JMATH::JPolynome::equals ( const JPolynome P,
const double  eps = std::numeric_limits<double>::min() 
) const
inline

Equality.

Parameters
Ppolynome
epsnumerical precision
Returns
true if polynomes identical; else false

Definition at line 194 of file JPolynome.hh.

196  {
197  if (this->size() == P.size()) {
198 
199  for (const_iterator p = this->begin(), q = P.begin(); p != this->end(); ++p, ++q) {
200  if (fabs(*p - *q) > eps) {
201  return false;
202  }
203  }
204 
205  return true;
206 
207  } else {
208 
209  return false;
210  }
211  }

Friends And Related Function Documentation

◆ operator>>

std::istream& operator>> ( std::istream &  in,
JPolynome object 
)
friend

Read polynome from input.

Parameters
ininput stream
objectpolynome
Returns
input stream

Definition at line 221 of file JPolynome.hh.

222  {
223  for (double x; in >> x; ) {
224  object.push_back(x);
225  }
226 
227  return in;
228  }

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const JPolynome object 
)
friend

Write polynome to output.

Parameters
outoutput stream
objectpolynome
Returns
output stream

Definition at line 238 of file JPolynome.hh.

239  {
240  for (JPolynome::const_iterator i = object.begin(); i != object.end(); ++i) {
241  out << ' ' << *i;
242  }
243 
244  return out;
245  }

The documentation for this class was generated from the following file:
JMATH::JPolynome
Polynome function object.
Definition: JPolynome.hh:26
JTOOLS::n
const int n
Definition: JPolint.hh:628
JMATH::JPolynome::getValue
double getValue(const double x) const
Function value.
Definition: JPolynome.hh:80