-
-
Notifications
You must be signed in to change notification settings - Fork 513
Open
Description
There seems to be a bug with the eigen value finder.
The following code produces a tri-diagonal matrix with real eigenvalues:
pub fn legendre_nodes(size: usize) -> Vec<f64>
{
let n = size;
let mut matrix = nalgebra::DMatrix::<f64>::zeros(n, n);
let a_fn = |i| (2. * i as f64 - 1.) / i as f64;
let c_fn = |i| (i as f64 - 1.) / i as f64;
for i in 1..=n
{
let a = a_fn(i);
let an = a_fn(i + 1);
let cn = c_fn(i + 1);
let beta = (cn / (a * an)).sqrt();
if i < size
{
matrix[(i, i - 1)] = beta;
matrix[(i - 1, i)] = beta;
}
}
println!("{:.2}", matrix);
let evals = matrix.eigenvalues().unwrap();
let mut res: Vec<_> = evals.iter().copied().collect();
for e in &evals
{
println!("{}", e);
}
res
}
Or alternatively:
┌ ┐
│ 0.00 0.58 0.00 0.00 │
│ 0.58 0.00 0.52 0.00 │
│ 0.00 0.52 0.00 0.51 │
│ 0.00 0.00 0.51 0.00 │
└ ┘
I traced the problem down to delimit_subproblem
. The start and the end get stuck at values 0 and 3 respectively and never update beyond that.
Metadata
Metadata
Assignees
Labels
No labels