Isis 3 Programmer Reference
BasisFunction.cpp
Go to the documentation of this file.
1 
23 #include <iostream>
24 #include "BasisFunction.h"
25 #include "IException.h"
26 #include "IString.h"
27 
28 namespace Isis {
29 
45  BasisFunction::BasisFunction(const QString &name, int numVars, int numCoefs) {
46 
47  p_name = name;
48  p_numVars = numVars;
49  p_numCoefs = numCoefs;
50  }
51 
52 
58  void BasisFunction::SetCoefficients(const std::vector<double> &coefs) {
59 
60  if ( (int)coefs.size() != p_numCoefs ) {
61  QString msg = "Unable to set coefficients vector. The size of the given vector ["
62  + toString((int)coefs.size()) + "] does not match number of coefficients "
63  "in the basis equation [" + toString(p_numCoefs) + "]";
65  }
66 
67  p_coefs = coefs;
68  }
69 
70 
80  double BasisFunction::Evaluate(const std::vector<double> &vars) {
81 
82  if ( (int)vars.size() != p_numVars ) {
83  QString msg = "Unable to evaluate function for the given vector of values. "
84  "The size of the given vector ["
85  + toString((int)vars.size()) + "] does not match number of variables "
86  "in the basis equation [" + toString(p_numVars) + "]";
88  }
89 
90  Expand(vars);
91 
92  if ( (int)p_terms.size() != p_numCoefs ) {
93  QString msg = "Unable to evaluate function for the given vector of values. "
94  "The number of terms in the expansion ["
95  + toString( (int)p_terms.size() ) + "] does not match number of coefficients "
96  "in the basis equation [" + toString(p_numCoefs) + "]";
98  }
99 
100  double result = 0.0;
101 
102  for (int i = 0; i < p_numCoefs; i++) {
103  result += p_coefs[i] * p_terms[i];
104  }
105 
106  return result;
107  }
108 
109 
117  double BasisFunction::Evaluate(const double &var) {
118 
119  std::vector<double> vars;
120  vars.push_back(var);
121  return BasisFunction::Evaluate(vars);
122  }
123 
124 
139  void BasisFunction::Expand(const std::vector<double> &vars) {
140  p_terms = vars;
141  }
142 }
void SetCoefficients(const std::vector< double > &coefs)
Set the coefficients for the equation.
int p_numVars
The number of variables in the equation. Call it by using Variables()
BasisFunction(const QString &name, int numVars, int numCoefs)
Creates a BasisFunction object.
std::vector< double > p_terms
A vector of the terms in the equation.
std::vector< double > p_coefs
A vector of the coefficients in the equation.
int p_numCoefs
The number of coefficients 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
virtual void Expand(const std::vector< double > &vars)
This is the function you should replace depending on your needs.
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
double Evaluate(const std::vector< double > &vars)
Compute the equation using the input variables.
Isis exception class.
Definition: IException.h:107
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
QString p_name
The name of the equation. Call it by using Name()