cheby 0.3.0

Unit-safe Chebyshev approximation and spectral numerics for Rust.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
//! Gauss-Chebyshev quadrature.

use crate::core::{ChebyScalar, NodeKind};

/// Integrate `f(x) / sqrt(1 - x^2)` on `[-1, 1]` with `N` roots.
pub fn integrate_weighted<T: ChebyScalar, const N: usize>(f: impl Fn(f64) -> T) -> T {
    let xs = crate::core::nodes::nodes::<N>(NodeKind::Gauss);
    let mut sum = T::zero();
    for x in xs {
        sum = sum + f(x);
    }
    sum * (core::f64::consts::PI / N as f64)
}