npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
opsRootsFromJacobiMatrix.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_OPSROOTSFROMJACOBIMATRIX_HH_
2 #define NPSTAT_OPSROOTSFROMJACOBIMATRIX_HH_
3 
4 /*!
5 // \file opsRootsFromJacobiMatrix.hh
6 //
7 // \brief Roots of orthogonal polynomials calculated from corresponding
8 // Jacobi matrices
9 //
10 // Author: I. Volobouev
11 //
12 // February 2023
13 */
14 
15 #include <vector>
16 #include <cassert>
17 #include <algorithm>
18 #include <stdexcept>
19 
20 #include "npstat/nm/Matrix.hh"
21 
22 namespace npstat {
23  /** The roots are returned in the increasing order */
24  template<class OPS>
25  std::vector<double> opsRootsFromJacobiMatrix(
26  const OPS& ops, const unsigned degree)
27  {
28  std::vector<double> roots(degree);
29  if (degree)
30  {
31  if (degree > ops.maxDegree()) throw std::invalid_argument(
32  "In npstat::opsRootsFromJacobiMatrix: "
33  "degree argument is out of range");
34  const Matrix<double> jacobiMat = ops.jacobiMatrix(degree);
35  assert(jacobiMat.nRows() == degree);
36  assert(jacobiMat.nColumns() == degree);
37  if (degree == 1U)
38  roots[0] = jacobiMat[0][0];
39  else
40  jacobiMat.tdSymEigen(&roots[0], degree);
41  const double s = ops.scale();
42  const double shift = ops.location();
43  if (!(shift == 0.0 && s == 1.0))
44  for (unsigned i=0; i<degree; ++i)
45  roots[i] = roots[i]*s + shift;
46  std::sort(roots.begin(), roots.end());
47  }
48  return roots;
49  }
50 }
51 
52 #endif // NPSTAT_OPSROOTSFROMJACOBIMATRIX_HH_
Template matrix class.
unsigned nRows() const
Definition: Matrix.hh:155
void tdSymEigen(Numeric *eigenvalues, unsigned lenEigenvalues, Matrix *eigenvectors=0, EigenMethod m=EIGEN_RRR) const
Definition: AbsArrayProjector.hh:14
std::vector< double > opsRootsFromJacobiMatrix(const OPS &ops, const unsigned degree)
Definition: opsRootsFromJacobiMatrix.hh:25