This chapter describes routines for computing Chebyshev approximations to univariate functions. A Chebyshev approximation is a truncation of the series f(x) = \sum c_n T_n(x), where the Chebyshev polynomials T_n(x) = \cos(n \arccos x) provide an orthogonal basis of polynomials on the interval [-1,1] with the weight function 1 / \sqrt{1-x^2}. The first few Chebyshev polynomials are, T_0(x) = 1, T_1(x) = x, T_2(x) = 2 x^2 - 1. For further information see Abramowitz & Stegun, Chapter 22.
GSL::Cheb
classGSL::Cheb.alloc(n)
GSL::Cheb#init(f, a, b)
ex: Approximate a step function defined in (0, 1) by a Chebyshev series of order 40.
f = GSL::Function.alloc { |x| if x < 0.5 0.25 else 0.75 end } cs = GSL::Cheb.alloc(40) cs.init(f, 0, 1)
GSL::Cheb#eval(x)
GSL::Cheb#eval_n(n, x)
GSL::Cheb#calc_deriv()
GSL::Cheb#deriv()
GSL::Cheb#calc_integ()
GSL::Cheb#integ()
#!/usr/bin/env ruby require("gsl") f = GSL::Function.alloc { |x| if x < 0.5 0.25 else 0.75 end } n = 1000 order = 40 cs = GSL::Cheb.alloc(order) cs.init(f, 0, 1) x = Vector.linspace(0, 1, n) ff = f.eval(x) r10 = cs.eval_n(10, x) r40 = cs.eval(x) GSL::graph(x, ff, r10, r40)
See also the example scripts in examples/cheb/
.