Crate roots

source ·
Expand description

A set of functions to find real roots of numerical equations.

This crate contains various algorithms for numerical and analytical solving of 1-variable equations like f(x)=0. Only real roots are calculated. Multiple (double etc.) roots are considered as one root.

Use

Functions find_root_* try to find a root of any given closure function by iterative approximations. Conditions for success/failure can be customized by implementing the Convergency trait. Functions find_roots_* return all roots of several simple equations at once.

Structs

Convergency provider for debugging. It will print out the error at each iteration.
Interval between two samples, including these samples
Definition of the quadratic equation ax^2 + bx + c
Pair of the independent variable x and the function value y=F(x)
A very basic convergency rules that must be sufficient for many cases. The absolute precision is the same for x and y axes, no relative precision.

Enums

Sorted and unique list of roots of an equation.
Possible errors

Traits

The way to check if the algorithm has finished by either finding a root or reaching the iteration limit.
Generic type that lists functions and constants needed in calculations. Default implementations for f32 and f64 are provided.

Functions

Find a root of the function f(x) = 0 using the Brent method.
Find a root of the function f(x) = 0 using inverse quadratic approximation.
Find a root of the function f(x) = 0 using the Newton-Raphson method.
Find a root of the function f(x) = 0 using the Illinois modification of the regula falsi method.
Find a root of the function f(x) = 0 using the secant method.
Solves a bi-quadratic equation a4x^4 + a2x^2 + a0 = 0.
Solves a cubic equation a3x^3 + a2x^2 + a1*x + a0 = 0.
Solves a depressed cubic equation x^3 + a1*x + a0 = 0.
Solves a normalized cubic equation x^3 + a2x^2 + a1x + a0 = 0.
Find all roots of the normalized polynomial by finding eigen numbers of the corresponding matrix. (Converted from Java by stiv-yakovenko)
Solves a linear equation a1*x + a0 = 0.
Solves a quadratic equation a2x^2 + a1x + a0 = 0.
Solves a quartic equation a4x^4 + a3x^3 + a2x^2 + a1x + a0 = 0.
Solves a depressed quartic equation x^4 + a2x^2 + a1x + a0 = 0.
Find all roots of the normalized polynomial x^n + a[0]*x^(n-1) + a[1]*x^(n-2) + … + a[n-1] = 0 using the Sturm’s theorem recursively.