Math::Polynomial::Chebyshev

Raku package with functionalities based on Chebyshev polynomials.

Math::Polynomial::Chebyshev

Raku package for functionalities based on Chebyshev polynomials.

Installation

From Zef ecosystem:

zef install Math::Polynomial::Chebyshev 

From GitHub:

zef install https://github.com/antononcube/Raku-Math-Polynomial-Chebyshev.git

Usage examples

Evaluate the numerical value of the Chebyshev polynomial of first kind :

use Math::Polynomial::Chebyshev;

chebyshev-t(2, 0.3)
# -0.82

The default method is "recursive":

chebyshev-t(2, 6, method => 'recursive')
# 71

Here is an invocation of the "trigonometric" method:

chebyshev-t(2, 3, method => 'trigonometric')
# 17

Remark: Currently, the trigonometric method is implemented only for the Chebyshev polynomials of first kind (Chebyshev-T.)

Plot the 7th Chebyshev-T polynomial:

use Text::Plot;

my @x = (-1, -0.99 ... 1);
text-list-plot(@x, chebyshev-t(6, @x), width => 60)
# +---+------------+-----------+------------+------------+---+      
# |                                                          |      
# +   *         ******                    *****          *   +  1.00
# |   *         *    **                  **    *         *   |      
# +            *      **                **     **            +  0.50
# |   *       **       *               **       **       *   |      
# |   *       *         *              *         *       *   |      
# +          *          **            *           *          +  0.00
# |    *     *           **          **           *     *    |      
# |    *    *             **        **             *    *    |      
# +    *   **              **      **              **  **    + -0.50
# |     * **                **    **                *  *     |      
# +     ***                  ******                  ***     + -1.00
# |                                                          |      
# +---+------------+-----------+------------+------------+---+      
#     -1.00        -0.50       0.00         0.50         1.00

Here we make a Chebyshev-T function:

chebyshev-u(4)
# -> ;; $_? is raw = OUTER::<$_> { #`(Block|2377734473048) ... }

A list of Chebyshev polynomials can be used as a basis for the models in "Math::Fitting", [AAp2]. Here is an example:

use Math::Fitting;

my @basis = (^4).map({ chebyshev-t($_) });
my @data = [2.rand - 1, 10.rand] xx 20;

my &lm = linear-model-fit(@data, :@basis);
# Math::Fitting::FittedModel(type => linear, data => (20, 2), response-index => 1, basis => 4)

Here are plots:

my @fit = (-1, -0.98 ... 1).map({ [$_, &lm($_)] });
say <fit data> Z=> <* ā–”>;
say text-list-plot([@fit, @data])
# (fit => * data => ā–”)
# +---+------------+-----------+------------+------------+---+       
# +                                                          +  10.00
# |                                           ā–”              |       
# |                                ā–”  ā–”                      |       
# +                                                     ā–”    +   8.00
# |                               ā–”         ****▔▔****  ▔▔   |       
# +                                 ********          ****   +   6.00
# |                           *******        ā–”               |       
# +                   ā–”  ******  ā–”                 ā–”         +   4.00
# |   ā–”***ā–”    **********                                    |       
# +       ****** ā–”                                   ā–”       +   2.00
# |                                          ā–”               |       
# |                          ā–”                               |       
# +                                                          +   0.00
# +---+------------+-----------+------------+------------+---+       
#     -1.00        -0.50       0.00         0.50         1.00

References

Articles

[WK1] Wolfram Koepf, "Efficient Computation of Chebyshev Polynomials in Computer Algebra". (1999), Computer Algebra Systems: A Practical Guide. 79-99.

[Wk1] Wikipedia entry, Chebyshev polynomials.

Packages

[AAp1] Anton Antonov, Text::Plot Raku package, (2022-2023), GitHub/antononcube.

[AAp2] Anton Antonov, Math::Fitting Raku package, (2024), GitHub/antononcube.

[SFp1] Solomon Foster, Math::ChebyshevPolynomial Raku package, (2013-2015), GitHub/colomon.

Math::Polynomial::Chebyshev v0.0.2

Raku package with functionalities based on Chebyshev polynomials.

Authors

  • Anton Antonov

License

Artistic-2.0

Dependencies

Test Dependencies

Provides

  • Math::Polynomial::Chebyshev

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.

Built with Podlite — the markup and publishing tools behind this site.