Isis 3.0 Programmer Reference
Back | Home
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 
49  void PolynomialUnivariate::Expand(const std::vector<double> &vars) {
50  p_terms.clear();
51  p_terms.push_back(1.0);
52 
53  for(int i = 1; i <= p_degree; i++) {
54  p_terms.push_back(p_terms[i-1]*vars[0]);
55  }
56  }
57 
58 
68  double PolynomialUnivariate::DerivativeVar(const double value) {
69 
70  double derivative = 0;
71 
72  for(int i = 1; i < Coefficients(); i++) {
73  derivative += i * Coefficient(i) * pow(value, i - 1);
74  }
75  return derivative;
76  }
77 
78 
79 
91  double PolynomialUnivariate::DerivativeCoef(const double value,
92  const int coefIndex) {
93  double derivative;
94 
95  if(coefIndex > 0 && coefIndex <= Coefficients()) {
96  derivative = pow(value, coefIndex);
97  }
98  else if(coefIndex == 0) {
99  derivative = 1;
100  }
101  else {
102  QString msg = "Unable to evaluate the derivative of the univariate polynomial for the given "
103  "coefficient index [" + toString(coefIndex) + "]. "
104  "Index is negative or exceeds degree of polynomial ["
105  + toString(Coefficients()) + "]";
107  }
108  return derivative;
109  }
110 
111 
112 } // end namespace isis
113 
int Coefficients() const
Returns the number of coefficients for the equation.
Definition: BasisFunction.h:80
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:154
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:38
double DerivativeVar(const double value)
This will take the Derivative with respect to the variable and evaluate at given value.
double Coefficient(int i) const
Returns the ith coefficient.
void Expand(const std::vector< double > &vars)
This is the the overriding virtual function that provides the expansion of the two input variables in...
Time based linear equation class.
Isis exception class.
Definition: IException.h:99
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.

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the ISIS Support Center
File Modified: 07/12/2023 23:26:00