Plotting polynomials
The package provides two helper functions to plot polynomials and any callable object, either in \([-1, 1]\) or along the unit circle.
from nlft_qsp import *
P = Polynomial([0.1, 0, -0.2, 0, 0.4]) # 0.1 - 0.2 x^2 + 0.4 x^4
def f(x):
return 0.2 - 0.3 * x ** 2
plot_chebyshev({
"Pretty polynomial": P,
"Pretty function": f
})
Note
plot_chebyshev implicitly takes the real part of the functions.
from nlft_qsp import *
import numpy as np
P = Polynomial([0.7, 0.1, 0.5, 0.4])
def f(z):
theta = np.angle(z)
if 0 < theta and theta < np.pi/2:
return 0.8
if -np.pi < theta and theta < -np.pi/2:
return 0.8
return 0.1
plot_fourier({
"Poly": P,
"Square wave": f
})
Note
Functions plotted by plot_fourier are meant to be of a complex variable \(z = e^{i\theta}\). Use np.angle as above to work with the variable \(\theta\).
Note
plot_fourier implicitly takes the absolute value of the functions.
Plotting using the Command Line Interface¶
The subcommand qspx plot uses the two above functions to plot any function specified as input, either as a file or as a Python expression. If P is saved in a file P.qspx, the first snippet above is equivalent to the following call:
Note that the -f flag should be put in front of arguments that are intended to be Python expressions. This call above will use plot_chebyshev and plot the given functions in \([-1, 1]\). Use the -u flag to plot along the unit circle.
Warning
When plotting \([-1, 1]\), the Python expression are with respect to the variable x, whereas functions to be plotted on the unit circle will be expected to be written with respect to variable z.