Skip to content

Infinite loop when computing eigen values #1528

@Makogan

Description

@Makogan

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions