isce3  0.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
Poly1d.h
1 //
2 // Author: Joshua Cohen
3 // Copyright 2017
4 //
5 
6 #pragma once
7 
8 #include "forward.h"
9 
10 #include <stdexcept>
11 #include <string>
12 #include <vector>
13 
24 public:
25 
27  int order;
29  double mean;
31  double norm;
33  std::vector<double> coeffs;
34 
40  Poly1d(int ord, double mn, double nm) : order(ord), mean(mn), norm(nm), coeffs(ord+1) {}
41 
43  Poly1d() : Poly1d(-1,0.,1.) {}
44 
46  Poly1d(const Poly1d &p) : order(p.order), mean(p.mean), norm(p.norm), coeffs(p.coeffs) {}
47 
49  inline Poly1d& operator=(const Poly1d&);
50 
55  inline void setCoeff(int ind,double val);
56 
60  inline double getCoeff(int ind) const;
61 
65  double eval(double x) const;
66 
68  void printPoly() const;
69 
71  Poly1d derivative() const;
72 };
73 
75 operator=(const Poly1d &rhs) {
76  order = rhs.order;
77  mean = rhs.mean;
78  norm = rhs.norm;
79  coeffs = rhs.coeffs;
80  return *this;
81 }
82 
84 setCoeff(int idx, double val) {
85  if ((idx < 0) || (idx > order)){
86  std::string errstr = "Poly1d::setCoeff - Trying to set coefficient " +
87  std::to_string(idx+1) + " out of " + std::to_string(order+1);
88  throw std::out_of_range(errstr);
89  }
90  coeffs[idx] = val;
91 }
92 
94 getCoeff(int idx) const {
95  if ((idx < 0) || (idx > order)) {
96  std::string errstr = "Poly1d::getCoeff - Trying to get coefficient " +
97  std::to_string(idx+1) + " out of " + std::to_string(order+1);
98  throw std::out_of_range(errstr);
99  }
100  return coeffs[idx];
101 }
void printPoly() const
Print for debugging.
Definition: Poly1d.cpp:38
void setCoeff(int ind, double val)
Set coefficient by index.
Definition: Poly1d.h:84
double getCoeff(int ind) const
Get coefficient by index.
Definition: Poly1d.h:94
Poly1d & operator=(const Poly1d &)
Assignment operator.
Definition: Poly1d.h:75
double mean
Mean of the polynomial.
Definition: Poly1d.h:29
Poly1d(int ord, double mn, double nm)
Constructor.
Definition: Poly1d.h:40
Data structure for representing 1D polynomials.
Definition: Poly1d.h:23
double norm
Norm of the polynomial.
Definition: Poly1d.h:31
double eval(double x) const
Evaluate polynomial at x.
Definition: Poly1d.cpp:12
int order
Order of the polynomial.
Definition: Poly1d.h:27
std::vector< double > coeffs
Coefficients of the polynomial.
Definition: Poly1d.h:33
Poly1d(const Poly1d &p)
Copy constructor.
Definition: Poly1d.h:46
Poly1d()
Empty constructor.
Definition: Poly1d.h:43
Poly1d derivative() const
Return derivative of polynomial.
Definition: Poly1d.cpp:45

Generated for ISCE3.0 by doxygen 1.8.5.