interpolate::poly::chebyshev
On this page
Chebyshev series sum_k c_k T_k(u) on a domain [a, b], u the
affine map of x onto [-1, 1]. The basis of choice for
approximating smooth functions: interpolation at Chebyshev points
converges geometrically for analytic functions and never suffers
Runge's phenomenon.
Structs
ChebyshevSource
pub struct ChebyshevA Chebyshev series on [a, b]. It is a Curve (Clenshaw's
recurrence, O(n), backward stable) and takes + - * with another
series on the same domain or an f64.
use interpolate::{Chebyshev, Curve};
let c = Chebyshev::interpolate(f64::exp, 20, 0.0..1.0);
assert((c.at(0.3) - 0.3f64.exp()).abs() < 1e-14);
assert((c.integrate() - (1f64.exp() - 1.0)).abs() < 1e-14);
Sourcepub fn new(§coef: Vector<f64>, domain: Range<f64>) throws (InterpError) -> Chebyshev The series with coefficients
coef(ofT_0,T_1, ...) ondomain.nabiuse interpolate::{Chebyshev, Curve}; let t2 = try Chebyshev::new([0, 0, 1], -1.0..1.0); // 2x^2 - 1 assert(t2.at(0.5) == -0.5);The interpolant of
fat thenChebyshev points of the first kind ondomain,x_j = cos(pi (j + 1/2) / n)mapped, by the discrete cosine sum (O(n^2)). For analyticfthe error falls geometrically withn.nabiuse interpolate::{Chebyshev, Curve}; let runge = |x: f64| -> f64 { 1.0 / (1.0 + 25.0 * x * x) }; let c = Chebyshev::interpolate(runge, 200, -1.0..1.0); assert((c.at(0.7) - runge(0.7)).abs() < 1e-14);
Sourcepub fn fit(§x: Vector<f64>, y: Vector<f64>, deg: usize) throws (InterpError) -> Chebyshev The least-squares series of degree
degthrough(x, y)on the domain[min x, max x], by pivoted QR (linalg::lstsq) on the Chebyshev-Vandermonde matrix, which stays well conditioned at high degree.nabiuse interpolate::{Chebyshev, Curve}; let c = try Chebyshev::fit([0, 1, 2, 3, 4], [0, 1, 4, 9, 16], 2); assert((c.at(2.5) - 6.25).abs() < 1e-13);The coefficients of
T_0,T_1, ...nabiuse interpolate::Chebyshev; let c = try Chebyshev::new([1, 2], 0.0..1.0); assert(c.coefficients()[1] == 2.0);The domain
(a, b).nabiuse interpolate::Chebyshev; assert((try Chebyshev::new([1], 2.0..5.0)).domain() == (2.0, 5.0));The degree.
nabiuse interpolate::Chebyshev; assert((try Chebyshev::new([1, 0, 3], -1.0..1.0)).degree() == 2);The
m-th derivative (inx, so scaled by2 / (b - a)per order), by the backward recurrencec'_{k-1} = c'_{k+1} + 2k c_k.nabiuse interpolate::{Chebyshev, Curve}; let c = Chebyshev::interpolate(f64::sin, 25, 0.0..2.0); assert((c.deriv(1).at(1.0) - 1f64.cos()).abs() < 1e-13);The
m-th antiderivative, each one zero ata.nabiuse interpolate::{Chebyshev, Curve}; let c = Chebyshev::interpolate(f64::cos, 25, 0.0..2.0); assert((c.integ(1).at(1.5) - 1.5f64.sin()).abs() < 1e-14);The integral over the domain.
nabiuse interpolate::Chebyshev; let c = try Chebyshev::new([1], 0.0..3.0); assert(c.integrate() == 3.0);
Sourcepub fn roots(§self) throws (InterpError) -> Vector<f64> The real roots in the domain, rising, after dropping trailing coefficients at rounding level: eigenvalues of the colleague matrix (
linalg::eig) with imaginary part below 1e-6 and real part in[-1, 1](within 1e-6, so roots on the domain's ends stay), mapped toxand polished by Newton steps.nabiuse interpolate::Chebyshev; let c = Chebyshev::interpolate(f64::sin, 30, 1.0..10.0); let r = try c.roots(); assert(r.len() == 3 && (r[0] - f64::PI).abs() < 1e-13);
Sourcepub fn to_polynomial(§self) -> Polynomial The same function as a power series in
x. Converting loses digits for high degrees (the power basis is ill conditioned); keep the series for evaluation.nabiuse interpolate::{Chebyshev, Polynomial}; let t2 = try Chebyshev::new([0, 0, 1], -1.0..1.0); assert(t2.to_polynomial() == Polynomial::new([-1, 0, 2]));
Trait implementations 8
impl Curve for Chebyshevimpl ops::Add for Chebyshevimpl ops::Add<f64> for Chebyshevimpl ops::Sub for Chebyshevimpl ops::Sub<f64> for Chebyshevimpl ops::Mul for Chebyshevimpl ops::Mul<f64> for Chebyshevimpl ops::Neg for Chebyshev