Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.apo.nmsu.edu/Telescopes/TCC/html/cheby_8h_source.html
Дата изменения: Tue Sep 15 02:25:37 2015
Дата индексирования: Sun Apr 10 00:16:47 2016
Кодировка:

Поисковые слова: вечный календарь
lsst.tcc: include/tcc/cheby.h Source File
lsst.tcc  1.2.2-3-g89ecb63
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
cheby.h
Go to the documentation of this file.
1 #pragma once
2 /*
3 Chebyshev polynomial
4 */
5 #include <stdexcept>
6 #include <iostream>
7 #include <limits>
8 #include <sstream>
9 #include <vector>
10 
11 namespace tcc {
12 
30  public:
37  std::vector<double> params,
38  double minX = -1,
39  double maxX = 1)
40  :
41  params(params)
42  {
43  if (params.size() < 1) {
44  throw std::runtime_error("ChebyshevPolynomial called with empty vector");
45  }
46  if (minX >= maxX) {
47  std::ostringstream os;
48  os << "ChebyshevPolynomial minX=" << minX << " >= " << maxX << "=maxX";
49  throw std::runtime_error(os.str());
50  }
51  _initialize(minX, maxX);
52  }
53 
58  :
59  params(1)
60  {
61  _initialize(-1.0, 1.0);
62  }
63 
67  double getMinX() const { return _minX; };
68 
72  double getMaxX() const { return _maxX; };
73 
77  unsigned int getOrder() const { return this->params.size() - 1; };
78 
82  double operator() (double x) const {
83  double xPrime = (x + _offset) * _scale;
84 
85  if ((xPrime < -1.0) || (xPrime > 1.0)) {
86  return std::numeric_limits<double>::quiet_NaN();
87  }
88 
89  // Clenshaw function for solving the Chebyshev polynomial
90  // Non-recursive version from Kresimir Cosic
91  int const order = getOrder();
92  if (order == 0) {
93  return this->params[0];
94  } else if (order == 1) {
95  return this->params[0] + (this->params[1] * xPrime);
96  }
97  double cshPrev = this->params[order];
98  double csh = (2 * xPrime * this->params[order]) + this->params[order-1];
99  for (int i = order - 2; i > 0; --i) {
100  double cshNext = (2 * xPrime * csh) + this->params[i] - cshPrev;
101  cshPrev = csh;
102  csh = cshNext;
103  }
104  return (xPrime * csh) + this->params[0] - cshPrev;
105  }
106 
110  std::string __repr__() const;
111 
112  std::vector<double> params;
113 
114  private:
115  double _minX;
116  double _maxX;
117  double _scale;
118  double _offset;
119 
123  void _initialize(double minX, double maxX) {
124  _minX = minX;
125  _maxX = maxX;
126  _scale = 2.0 / (_maxX - _minX);
127  _offset = -(_minX + _maxX) * 0.5;
128  }
129  };
130 
131  std::ostream &operator<<(std::ostream &os, ChebyshevPolynomial const &cheby);
132 
133 }
ChebyshevPolynomial(std::vector< double > params, double minX=-1, double maxX=1)
Definition: cheby.h:36
std::vector< double > params
Definition: cheby.h:112
double getMaxX() const
Definition: cheby.h:72
double getMinX() const
Definition: cheby.h:67
std::string __repr__() const
Definition: cheby.cc:6
double operator()(double x) const
Definition: cheby.h:82
std::ostream & operator<<(std::ostream &os, ChebyshevPolynomial const &cheby)
Definition: cheby.cc:12
unsigned int getOrder() const
Definition: cheby.h:77