This page was generated from
doc/euclidean/polynomials.ipynb.
Interactive online version:
.
Polynomial Parametric Curves§
[1]:
import sympy as sp
sp.init_printing(order='grevlex')
[2]:
t = sp.symbols('t')
The coefficients are written as bold letters, because they are elements of a vector space (e.g. \(\mathbb{R}^3\)).
We are using bold symbols because apart from simple scalars (for one-dimensional functions), these symbols can also represent vectors in two- or three-dimensional space.
[3]:
coefficients = sp.Matrix(sp.symbols('a:dbm')[::-1])
coefficients
[3]:
$\displaystyle \left[\begin{matrix}\boldsymbol{d}\\\boldsymbol{c}\\\boldsymbol{b}\\\boldsymbol{a}\end{matrix}\right]$
Monomial basis functions:
[4]:
b_monomial = sp.Matrix([t**3, t**2, t, 1]).T
b_monomial
[4]:
$\displaystyle \left[\begin{matrix}t^{3} & t^{2} & t & 1\end{matrix}\right]$
[5]:
b_monomial.dot(coefficients)
[5]:
$\displaystyle \boldsymbol{d} t^{3} + \boldsymbol{c} t^{2} + \boldsymbol{b} t + \boldsymbol{a}$
This is a cubic polynomial in its canonical form (monomial basis).
Monomial basis functions:
[6]:
from helper import plot_basis
[7]:
plot_basis(*b_monomial, labels=b_monomial)
It doesn’t look like much, but every conceivable cubic polynomial can be formulated as exactly one linear combination of those basis functions.
Example:
[8]:
example_polynomial = (2 * t - 1)**3 + (t + 1)**2 - 6 * t + 1
example_polynomial
[8]:
$\displaystyle \left(2 t - 1\right)^{3} + \left(t + 1\right)^{2} - 6 t + 1$
[9]:
sp.plot(example_polynomial, (t, 0, 1));
[9]:
<sympy.plotting.plot.Plot at 0x7ff97a689a90>
Can be re-written with monomial basis functions:
[10]:
example_polynomial.expand()
[10]:
$\displaystyle 8 t^{3} - 11 t^{2} + 2 t + 1$
[ ]: