MDStressLab++
Polynomial.h
Go to the documentation of this file.
1 /*
2  * Polynomial.h
3  *
4  * Created on: Dec 21, 2019
5  * Author: Nikhil
6  */
7 
8 #ifndef SRC_POLYNOMIAL_H_
9 #define SRC_POLYNOMIAL_H_
10 
11 #include <deque>
12 #include <cmath>
13 
14 class Polynomial {
15 public:
16  Polynomial(const std::deque<double>& coefficients):coefficients(coefficients)
17  {}
18  Polynomial()=default;
19  virtual ~Polynomial(){}
20  std::deque<double> coefficients;
21 
22  double operator()(const double& argument) const
23  {
24  int degree= 0;
25  double value= 0;
26  for(const auto& coefficient : coefficients)
27  {
28  value= value + coefficient*pow(argument,degree);
29  degree++;
30  }
31 
32  return value;
33  }
34 
36  {
37  Polynomial p;
38  int degree= 0;
39  p.coefficients.push_back(0);
40  for(const auto& coefficient : coefficients)
41  {
42  p.coefficients.push_back(coefficient/(degree+1));
43  degree++;
44  }
45  return p;
46  }
47 };
48 
49 #endif /* SRC_POLYNOMIAL_H_ */
Polynomial(const std::deque< double > &coefficients)
Definition: Polynomial.h:16
Polynomial integrate() const
Definition: Polynomial.h:35
virtual ~Polynomial()
Definition: Polynomial.h:19
Polynomial()=default
double operator()(const double &argument) const
Definition: Polynomial.h:22
std::deque< double > coefficients
Definition: Polynomial.h:20