Mantid
Loading...
Searching...
No Matches
ChebyshevSeries.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7//-----------------------------------------------------------------------------
8// Includes
9//-----------------------------------------------------------------------------
11#include <algorithm>
12#include <cassert>
13
14//-----------------------------------------------------------------------------
15// Anonmouys static helpers
16//-----------------------------------------------------------------------------
17
18namespace Mantid::Kernel {
19
20//-----------------------------------------------------------------------------
21// Public members
22//-----------------------------------------------------------------------------
28ChebyshevSeries::ChebyshevSeries(const size_t degree) : m_bk(degree + 3, 0.0) {
29 // The algorithm requires computing upto n+2 terms so space is
30 // reserved for (n+1)+2 values.
31}
32
42double ChebyshevSeries::operator()(const std::vector<double> &c, const double x) {
43 const size_t degree(m_bk.size() - 3);
44 assert(c.size() >= degree + 1);
45
46 m_bk.resize(degree + 3);
47 std::fill(m_bk.begin(), m_bk.end(), 0.0);
48 for (size_t i = 0; i <= degree; ++i) {
49 const size_t k = degree - i;
50 m_bk[k] = c[k] + 2. * x * m_bk[k + 1] - m_bk[k + 2];
51 }
52 return m_bk[0] - x * m_bk[1];
53}
54
55} // namespace Mantid::Kernel
std::vector< double > m_bk
double operator()(const std::vector< double > &c, const double x)
ChebyshevSeries(const size_t degree)
Constructor for an n-th order polynomial.