Isis 3 Programmer Reference
PolynomialUnivariate.cpp
Go to the documentation of this file.
1 
23 #include <iostream>
24 #include <cmath>
25 
26 #include "PolynomialUnivariate.h"
27 #include "IString.h"
28 #include "IException.h"
29 
30 namespace Isis {
38  Isis::Basis1VariableFunction("PolynomialUnivariate", (degree + 1)) {
39  p_degree = degree;
40  }
41 
42 
49  PolynomialUnivariate::PolynomialUnivariate(int degree, std::vector<double> coeffs) :
50  Isis::Basis1VariableFunction("PolynomialUnivariate", (degree + 1)) {
51  p_degree = degree;
52  SetCoefficients(coeffs);
53  }
54 
55 
63  void PolynomialUnivariate::Expand(const std::vector<double> &vars) {
64  p_terms.clear();
65  p_terms.push_back(1.0);
66 
67  for(int i = 1; i <= p_degree; i++) {
68  p_terms.push_back(p_terms[i-1]*vars[0]);
69  }
70  }
71 
72 
82  double PolynomialUnivariate::DerivativeVar(const double value) {
83 
84  double derivative = 0;
85 
86  for(int i = 1; i < Coefficients(); i++) {
87  derivative += i * Coefficient(i) * pow(value, i - 1);
88  }
89  return derivative;
90  }
91 
92 
93 
105  double PolynomialUnivariate::DerivativeCoef(const double value,
106  const int coefIndex) {
107  double derivative;
108 
109  if(coefIndex > 0 && coefIndex <= Coefficients()) {
110  derivative = pow(value, coefIndex);
111  }
112  else if(coefIndex == 0) {
113  derivative = 1;
114  }
115  else {
116  QString msg = "Unable to evaluate the derivative of the univariate polynomial for the given "
117  "coefficient index [" + toString(coefIndex) + "]. "
118  "Index is negative or exceeds degree of polynomial ["
119  + toString(Coefficients()) + "]";
121  }
122  return derivative;
123  }
124 
125 
126 } // end namespace isis
127 
void SetCoefficients(const std::vector< double > &coefs)
Set the coefficients for the equation.
std::vector< double > p_terms
A vector of the terms in the equation.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:226
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:162
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
double DerivativeVar(const double value)
This will take the Derivative with respect to the variable and evaluate at given value.
void Expand(const std::vector< double > &vars)
This is the the overriding virtual function that provides the expansion of the two input variables in...
double Coefficient(int i) const
Returns the ith coefficient.
Time based linear equation class.
Isis exception class.
Definition: IException.h:107
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
double DerivativeCoef(const double value, const int coefIndex)
Evaluate the derivative of the polynomial defined by the given coefficients with respect to the coeff...
PolynomialUnivariate(int degree)
Create a PolynomialUnivariate object.
int p_degree
The order/degree of the polynomial.
int Coefficients() const
Returns the number of coefficients for the equation.
Definition: BasisFunction.h:80