#polynomial #approximation #chebyshev #embedded #no-alloc

no-std microcheby

Single variable function approximation using Chebyshev polynomials. Embedded friendly and no_std compatible.

2 releases

0.1.1 Jul 30, 2024
0.1.0 Jul 30, 2024

#658 in Math

MIT license

205KB
420 lines

microcheby

Crates.io Docs.rs

microcheby is a Rust library for computing and evaluating polynomial approximations of functions of one variable using using Chebyshev polynomials. The code is no_std compatible, does not depend on alloc and is optimized for resource constrained environments where every clock cycle counts. Optimizations include:

  • Clenshaw recursion for evaluating approximations.
  • Efficient loop free functions for evaluating low order approximations.
  • Even more efficient loop free evaluation if the range happens to be [-1, 1].
  • Approximation evaluation without divisions.

Installing

Add the following line to your Cargo.toml file:

microcheby = "0.1"

To use microcheby in a no_std environment:

microcheby = { version = "0.1", default-features = false }

Usage

See the crate documentation.

Chebyshev approximation

Sufficiently well behaved functions can be expressed as an infinite weighted sum of so called Chebyshev polynomials of increasing order. Such a sum is known as a Chebyshev expansion. If the target function is smooth enough, the coefficients (weights) of the expansion will typically converge to zero quickly and only the first few terms are needed to get a good approximation. For a truncated expansion with n terms, an estimate of the approximation error is given by the magnitude of coefficient n+1.

Below are some graphs showing how the approximation converges to the target function as the number of terms in the expansion increases. For smoother target functions, convergence is typically faster.

No runtime deps

Features