Example 6.63 from Axler's Linear Algebra Done Right 🙏
Goal: compute an approximation to the sine function that improves upon the Taylor Polynomial approximation from calculus.
- Let
$C[-\pi, \pi]$ denote the real inner product space of continuous real-valued functions on$[-\pi, \pi]$ with inner product$\langle f, g \rangle = \int_{-\pi}^{\pi} fg$ . - Let
$v \in C[-\pi, \pi]$ be the function$v(x) = \sin x$ - Let
$U$ denote the subspace$\mathcal{P}_{5}(\mathbb{R}) \subseteq C[-\pi, \pi]$ (the space of polynomials of degree at most$5$ with real coefficients) - The goal is to choose
$u \in U$ such that$\Vert v - u \Vert$ is as small as possible where
- The solution is given by the orthogonal projection of
$v(x) = \sin x$ onto$U = \mathcal{P}_{5}(\mathbb{R})$
Approach:
- Have standard basis of
$\mathcal{P}_{5}(\mathbb{R})$
- Compute orthonormal basis of
$\mathcal{P}_{5}(\mathbb{R})$ by applying the Gram-Schmidt procedure to the basis above. - The $k$th vector of the orthonormal basis is computed as:
- Compute the orthogonal projection of
$v(x) = \sin x$ onto$\mathcal{P}_{5}(\mathbb{R})$ by using the orthonormal basis found above and the formula:
- Install with
uv venv
uv pip install .
See code.
❯ python gs_poly_project.py
Creating orthonormal basis...
Projecting sin(x) onto orthonormal basis...
Projection: 0.00564311797634678*x**5 - 0.155271410633428*x**3 + 0.987862135574673*x
Largest relative error for x ∈ [3, π]: (x=3.0, error= 271.11)
The orthogonal projection (function) is given by (approximately):
The exact solution (see sympy output) equals:
Sine function, orthogonal projection and Taylor and approximation on
Sine function, orthogonal projection and Taylor and approximation on
Sine function, orthogonal projection and Taylor and approximation on