qmat.playgrounds.tibo.orthogonalPolynomials

Compute and display orthogonal polynomials of any degree using qmat

 1import numpy as np
 2import matplotlib.pyplot as plt
 3from qmat.nodes import NodesGenerator
 4
 5deg = 100
 6"""polynomial degree"""
 7
 8polyType = "CHEBY-1"
 9"""type of polynomial"""
10
11t = np.linspace(-1, 1, num=1000000)
12"""plotting points"""
13
14gen = NodesGenerator(polyType)
15alpha, beta = gen.getOrthogPolyCoefficients(deg+1)
16
17# Generate monic polynomials (leading coefficient is 1)
18if deg == 0:
19    out = 0*t + 1.
20else:
21    pi = np.array([np.zeros_like(t) for i in range(3)])
22    pi[1:] += 1
23    for alpha_j, beta_j in zip(alpha, beta):
24        pi[2] *= (t-alpha_j)
25        pi[0] *= beta_j
26        pi[2] -= pi[0]
27        pi[0] = pi[1]
28        pi[1] = pi[2]
29    out = np.copy(pi[2])
30
31# Scaling (depends on the kind of the polynomial)
32if polyType == "CHEBY-1":
33    out *= 2**deg
34    ylim = (-1.1, 1.1)
35elif polyType == ["CHEBY-2", "CHEBY-3", "CHEBY-4"]:
36    out *= 2**(deg+(deg>0))
37    ylim = (-1.6, 1.6)
38
39plt.plot(t, out, label=f"{polyType}, $p={deg}$")
40plt.ylim(*ylim)
41plt.legend()
42plt.xlabel("$t$")
43plt.ylabel("$p(t)$")
44plt.grid(True)

Attributes

deg

polynomial degree

polyType

type of polynomial

t

plotting points

gen

out

ylim

Module Contents

deg = 100

polynomial degree

polyType = 'CHEBY-1'

type of polynomial

t

plotting points

gen
out
ylim