39 : m_gamma(gamma), m_delta(delta), m_n(m_delta.size())
40 {
GISMO_ASSERT( m_delta.size() == m_gamma.size() + 1,
"Size mismatch." ); }
57 for (
size_t i=0;i<m_n;++i)
60 + ( i<m_n-1 ?
math::abs(m_gamma[i]) : (T)(0) )
61 + ( i>0 ? math::abs(m_gamma[i-1]) : (T)(0) );
94 list.add(0,0,m_delta[0]);
95 for (
size_t i = 1; i<m_n;i++)
97 list.add(i,i-1,m_gamma[i-1]);
98 list.add(i-1,i,m_gamma[i-1]);
99 list.add(i,i,m_delta[i]);
113 std::pair<T,T>
eval( T lambda )
115 std::vector<T> value(m_n+1);
116 std::vector<T> deriv(m_n+1);
119 value[1] = m_delta[0]-lambda;
122 for (
size_t k=2; k<m_n+1; ++k)
124 value[k] = (m_delta[k-1]-lambda) * value[k-1] - m_gamma[k-2]*m_gamma[k-2]*value[k-2];
125 deriv[k] = (m_delta[k-1]-lambda) * deriv[k-1] - value[k-1] - m_gamma[k-2]*m_gamma[k-2]*deriv[k-2];
127 return std::pair<T,T>(value[m_n],deriv[m_n]);
145 while (iter < maxIter && res > tol)
147 const std::pair<T,T> ev =
eval(x_old);
148 const T& value = ev.first;
149 const T& deriv = ev.second;
151 x_new = x_old - value/deriv;
161 const std::vector<T>& m_gamma;
162 const std::vector<T>& m_delta;
Class that provides a container for triplets (i,j,value) to be filled in a sparse matrix...
Definition: gsSparseMatrix.h:33
std::pair< T, T > eval(T lambda)
Evalutates characteristic polynomial.
Definition: gsLanczosMatrix.h:113
T newtonIteration(T x0, index_t maxIter, T tol)
Newton iteration for searching the zeros of the characteristic polynomial.
Definition: gsLanczosMatrix.h:139
gsLanczosMatrix(const std::vector< T > &gamma, const std::vector< T > &delta)
Constructor for the Lanczos matrix The Lanczos matrix is a symmetric tridiagonal matrix with diagonal...
Definition: gsLanczosMatrix.h:38
Class for representing a Lanczos matrix and calculating its eigenvalues.
Definition: gsLanczosMatrix.h:27
#define index_t
Definition: gsConfig.h:32
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
T minEigenvalue(index_t maxIter=20, T tol=1.e-6)
Calculates the smallest eigenvalue.
Definition: gsLanczosMatrix.h:76
gsSparseMatrix< T > matrix()
This function returns the Lanczos matrix as gsSparseMatrix.
Definition: gsLanczosMatrix.h:88
EIGEN_STRONG_INLINE abs_expr< E > abs(const E &u)
Absolute value.
Definition: gsExpressions.h:4486
T maxEigenvalue(index_t maxIter=20, T tol=1.e-6)
Calculates the largest eigenvalue.
Definition: gsLanczosMatrix.h:50