{ "cells": [ { "cell_type": "markdown", "id": "9de7bd42-3e59-40ce-9afd-e6e1a020596e", "metadata": {}, "source": [ "# Chebyshev polynomials" ] }, { "cell_type": "markdown", "id": "a7535578-9bde-4d0b-bdc4-11bb1903a767", "metadata": {}, "source": [ "**Chebyshev polynomials** is a particular form of *special functions* that are important in\n", "numerical analysis.\n", "\n", "Chebyshev polynomials (of the first kind) are defined as follows:\n", "\n", "$$T_{n}\\left( x \\right) \\equiv \\cos \\left(n \\arccos x \\right), \\qquad n = 0, 1, 2, \\ldots \\quad -1 \\le x \\le 1.$$\n", "\n", "The polynomials are named after the mathematician Pafnuty Chebyshev. The\n", "letter `T` is used because of the alternative transliterations of\n", "the name Chebyshev as Tchebycheff or Tchebyshev.\n", "\n", "The first few Chebyshev polynomials are as follows:\n", " \n", "$$T_{0}(x) = 1, \\quad T_{1}(x) = x , \\quad T_2(x) = 2x^2 - 1,\n", " \\quad T_3(x) = 4x^3 - 3x .$$\n", "\n", "Chebyshev polynomial $T_n(x)$ satisfy the following recurrence relations:\n", "\n", "$$T_{n+1}(x) = 2 \\, x \\,T_{n}(x) - T_{n-1}(x), \\qquad n = 1, 2, \\ldots$$" ] }, { "cell_type": "code", "execution_count": null, "id": "2c4ef57d", "metadata": {}, "outputs": [], "source": [ "using PyPlot" ] }, { "cell_type": "code", "execution_count": null, "id": "1aa3aab0", "metadata": {}, "outputs": [], "source": [ "\"\"\"\n", " mycheb(n, x)\n", "\n", "Calculate Chebyshev polynomials using the recurrence relation T_{n+1} = 2*x*T_nc - T_(n-1}\n", "\"\"\"\n", "function mycheb(n, x)\n", " \n", " tp = 1.0\n", " if n == 0\n", " return tp\n", " end\n", " \n", " tc = x\n", " if n == 1\n", " return tc\n", " end\n", "\n", " for i = 1:(n-1)\n", " tn = 2*x*tc - tp\n", " tp = tc\n", " tc = tn\n", " end\n", " \n", " return tc\n", " \n", "end\n" ] }, { "cell_type": "code", "execution_count": null, "id": "3fc4b76e", "metadata": {}, "outputs": [], "source": [ "np = 100\n", "x = range(-1.0, 1.0, np);" ] }, { "cell_type": "code", "execution_count": null, "id": "8d64dc9f", "metadata": {}, "outputs": [], "source": [ "for n = [2, 3, 5]\n", " plot(x, mycheb.(n, x), label=L\"T_%$n(x)\")\n", "end\n", "grid(true)\n", "title(\"Chebyshev polynomials\")\n", "xlabel(\"x\")\n", "ylabel(\"y(x)\")\n", "legend()\n", "ylim(-1.1, 1.1); # optional in this example" ] }, { "cell_type": "code", "execution_count": null, "id": "1bb63038", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "@webio": { "lastCommId": null, "lastKernelId": null }, "kernelspec": { "display_name": "Julia 1.10.5", "language": "julia", "name": "julia-1.10" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.10.5" } }, "nbformat": 4, "nbformat_minor": 5 }