Isis 3 Programmer Reference
PolynomialUnivariate.cpp
1 
6 /* SPDX-License-Identifier: CC0-1.0 */
7 #include <iostream>
8 #include <cmath>
9 
10 #include "PolynomialUnivariate.h"
11 #include "IString.h"
12 #include "IException.h"
13 
14 namespace Isis {
22  Isis::Basis1VariableFunction("PolynomialUnivariate", (degree + 1)) {
23  p_degree = degree;
24  }
25 
26 
34  PolynomialUnivariate::PolynomialUnivariate(int degree, std::vector<double> coeffs) :
35  Isis::Basis1VariableFunction("PolynomialUnivariate", (degree + 1)) {
36  p_degree = degree;
37  SetCoefficients(coeffs);
38  }
39 
40 
48  void PolynomialUnivariate::Expand(const std::vector<double> &vars) {
49  p_terms.clear();
50  p_terms.push_back(1.0);
51 
52  for(int i = 1; i <= p_degree; i++) {
53  p_terms.push_back(p_terms[i-1]*vars[0]);
54  }
55  }
56 
57 
67  double PolynomialUnivariate::DerivativeVar(const double value) {
68 
69  double derivative = 0;
70 
71  for(int i = 1; i < Coefficients(); i++) {
72  derivative += i * Coefficient(i) * pow(value, i - 1);
73  }
74  return derivative;
75  }
76 
77 
78 
90  double PolynomialUnivariate::DerivativeCoef(const double value,
91  const int coefIndex) {
92  double derivative;
93 
94  if(coefIndex > 0 && coefIndex <= Coefficients()) {
95  derivative = pow(value, coefIndex);
96  }
97  else if(coefIndex == 0) {
98  derivative = 1;
99  }
100  else {
101  QString msg = "Unable to evaluate the derivative of the univariate polynomial for the given "
102  "coefficient index [" + toString(coefIndex) + "]. "
103  "Index is negative or exceeds degree of polynomial ["
104  + toString(Coefficients()) + "]";
105  throw IException(IException::Programmer, msg, _FILEINFO_);
106  }
107  return derivative;
108  }
109 
110 
111 } // end namespace isis
Isis::BasisFunction::SetCoefficients
void SetCoefficients(const std::vector< double > &coefs)
Set the coefficients for the equation.
Definition: BasisFunction.cpp:42
Isis::PolynomialUnivariate::p_degree
int p_degree
The order/degree of the polynomial.
Definition: PolynomialUnivariate.h:51
Isis::PolynomialUnivariate::PolynomialUnivariate
PolynomialUnivariate(int degree)
Create a PolynomialUnivariate object.
Definition: PolynomialUnivariate.cpp:21
Isis::PolynomialUnivariate::DerivativeVar
double DerivativeVar(const double value)
This will take the Derivative with respect to the variable and evaluate at given value.
Definition: PolynomialUnivariate.cpp:67
Isis::toString
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:211
Isis::PolynomialUnivariate::DerivativeCoef
double DerivativeCoef(const double value, const int coefIndex)
Evaluate the derivative of the polynomial defined by the given coefficients with respect to the coeff...
Definition: PolynomialUnivariate.cpp:90
Isis::IException
Isis exception class.
Definition: IException.h:91
Isis::Basis1VariableFunction
Time based linear equation class.
Definition: Basis1VariableFunction.h:50
Isis::PolynomialUnivariate::Expand
void Expand(const std::vector< double > &vars)
This is the the overriding virtual function that provides the expansion of the two input variables in...
Definition: PolynomialUnivariate.cpp:48
Isis::IException::Programmer
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:146
Isis::BasisFunction::p_terms
std::vector< double > p_terms
A vector of the terms in the equation.
Definition: BasisFunction.h:127
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::BasisFunction::Coefficients
int Coefficients() const
Returns the number of coefficients for the equation.
Definition: BasisFunction.h:64
Isis::BasisFunction::Coefficient
double Coefficient(int i) const
Returns the ith coefficient.
Definition: BasisFunction.h:107