Skip to content

antononcube/Raku-Math-Polynomial-Chebyshev

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 $T_2(3)$:

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|5022763304568) ... }

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 is a plot of the data and the fit:

my @fit = (-1, -0.98 ... 1).map({ [$_, &lm($_)] });
say <fit data> Z=> <* □>;
say text-list-plot([@fit, @data])
# (fit => * data => □)
# +---+------------+-----------+------------+------------+---+       
# |                                                      *   |       
# +                                                     **   +  12.00
# +                                                    **    +  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.

Releases

No releases published

Packages

No packages published

Languages