Skip to content

Problem calculating fourth-degree poly roots #5

@m2-farzan

Description

@m2-farzan

Unfortunately the library fails to evaluate roots of fourth-degree equations. Take this code for example:

use rustnomial::{Polynomial};

fn main() {
    let poly = Polynomial::<f64>::new(vec![1.0, 1.0, 1.0, 1.0, 1.0]);
    let roots = poly.roots();
    match roots {
        rustnomial::Roots::OnlyRealRoots(_) => {
            println!("roots() returned `Only Real Roots`");
        },
        _ => {
            println!("roots() returned some other type.");
        }
    }
}

Running this with rustnomial = "0.2.0" prints:

roots() returned `Only Real Roots`

while in fact x^4 + x^3 + x^2 + x + 1 has no real roots. The vector V in OnlyRealRoots(V) is empty too.

Some other times, the library returns OnlyRealRoots(V) with V containing only real roots, skipping complex ones.

Maybe I'm missing something here, but my understanding was that the library should have returned ManyComplexRoots in these cases.

BTW, thanks for the nice package. I'm using it in an educational project.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions