coefficients → integral metric → orthonormal basis
Notebook
Ch4-2 Vector Spaces of Polynomials.ipynb
Lab goal
Separate polynomial coefficients from function values, derive the Gram matrix, and project a polynomial using the lecture’s integral inner product.
Lecture-note concepts
Polynomial vector spaces
Integral inner product
Gram matrix
Gram–Schmidt
Legendre normalization
Code extensionUse coefficients in ascending powers throughout; correct the missing predecessor in the source Gram–Schmidt loop and verify every pair of basis polynomials.
A polynomial is a vector in a finite-dimensional function space. Its coefficient array is a coordinate representation, not the definition of its length. We use the lecture’s inner product ⟨f,g⟩=∫−11f(t)g(t)dt and start with P2, the polynomials of degree at most two, including the zero polynomial.
⟨u,v⟩;∥u∥;u⊥v
An inner product gives one real number, ∥u∥=⟨u,u⟩ is its induced norm, and u⊥v means ⟨u,v⟩=0. The lecture writes |u| for this norm. In Euclidean space the default is uTv and the norm is ∥u∥2; for polynomials it is the stated integral norm.
φ;θ;θ^
This chapter uses φ for an angle and θ for model coefficients in Lab 4.4. The lecture sometimes uses θ for the angle too; the distinction here prevents mixing an angle with a coefficient vector. A hat marks a minimizing coefficient, not a unit vector.
A;G;Q;R;P
A stores input columns in the Euclidean QR and least-squares labs. G denotes a Gram matrix of inner products, including the polynomial metric (which the lecture locally calls A). Q stores orthonormal columns, R stores their reconstruction coefficients, and P projects onto a subspace. These matrices have different jobs and shapes.
Pn;B=(1,t,…,tn)
Pn has dimension n + 1. “Degree at most n” includes lower degrees and the zero polynomial; polynomials of degree exactly n do not form a vector space. B is an ordered basis, so order determines which coefficient goes with each term.
f(t)=c0+c1t+c2t2;[f]B=c
The coordinate vector c=(c0,c1,c2)T has three entries. The scalar t is the argument; f(t) is the value at that argument. This page uses t instead of the lecture’s occasional x to distinguish an argument from a coordinate vector.
Gij=∫−11ti+jdt,i,j=0,…,n
These indices label monomial degrees, starting at 0. Gij=0 for odd i+j and 2/(i+j+1) for even i+j. The lecture calls this Gram matrix A locally; we call it G to keep A for the design matrix in 4.3–4.4.
⟨f,g⟩=cTGd;∥f∥2=cTGc
c and d are the coordinates of f and g in B. The plain coordinate dot product cTd is generally different. For example, the coordinate arrays for 1 and t2 have dot product 0, but their integral inner product is 2/3.
q0,q1,q2;C=[[q0]B∣[q1]B∣[q2]B]
We label polynomial basis vectors by degree, beginning at 0; these correspond to the lecture’s w1,w2,w3. C has coefficient columns. Orthonormality for this metric means CTGC=I3, not CTC=I3.
Legendre Pk(t);normalized qk(t)
Standard Legendre polynomials satisfy Pk(1)=1 and ∫−11Pk2=2/(2k+1). Multiplying by (2k+1)/2 gives qk of unit integral norm. Endpoint normalization and unit-norm normalization are different.
NumPy ascending powers: [c0,c1,c2]
numpy.polynomial.polynomial uses increasing powers: [0,1] is t and [0,0,1] is t2. The original notebook uses legacy np.polyval/np.polyint, whose arrays run in the opposite order. We use the modern ascending convention consistently and do not mix the two APIs.
Key ideas
Terms you will use
Polynomial coordinatesf(t)=c0+c1t+c2t2
The ordered monomial basis identifies a polynomial with a coefficient vector.
Keep in mind A coefficient is not a sampled function value.
Integral inner product⟨f,g⟩=∫−11f(t)g(t)dt=cTGd
Integrate the product of two functions over the specified interval.
Keep in mind Changing the interval or weight changes the geometry.
Orthonormal polynomialsCTGC=I
Basis functions have unit integral norms and zero cross inner products.
Keep in mindCTC checks a different metric.
Change the input
See the geometry respond
Project f(t)=tn onto Pk using ∫−11f(t)g(t)dt. Compare the target, its closest polynomial, and the residual over the whole interval. The curve’s vertical axis shows values, not coefficient coordinates.
Integrated squared error
0.17778
Largest ∣⟨e,qj⟩∣
0
f(t)=t2
p(t) · closest polynomial
e(t) = f(t) − p(t)
p(t)=0.33333. The residual is orthogonal in the integral inner product, even where the curves have different heights.
Lab 4.2 · Geometry of functions
Orthogonalize 1, t,t2 and find the best line
Use the lecture’s low-degree example before generalizing. Coefficients run in ascending powers everywhere in this lab.
Select a line to see its action, array shape, and concrete operation.
t has coordinates (0,1,0)T;t2 has coordinates (0,0,1)T in (1,t,t2). Their function-space inner product is defined by an integral.
coordinates of t∣t2
001001
After
?
Reveal to compare.
Connect the steps
Why polynomial geometry needs its own inner product
01 An integral can give lengths and angles to functions
The integral is symmetric and bilinear. Also ∫−11f(t)2dt≥0. A nonzero polynomial is continuous and cannot vanish throughout an interval; somewhere its squared value is positive on a neighborhood, so the integral is strictly positive. Thus the integral defines an inner product on Pn.
For f(t)=t and g(t)=t2, their product t3 is odd. Its negative and positive signed areas cancel, giving inner product 0. This is function-space orthogonality; crossing curves or a right angle between their drawn tangents is not the definition.
⟨t,t2⟩=0;∥t∥2=32;∥t2∥2=52
02 The Gram matrix translates function geometry into coordinates
Expand f=∑iciti and g=∑jdjtj. Bilinearity lets us move the finite sums outside the integral, leaving ∑cidj∫ti+j=cTGd. Symmetry comes from swapping i and j.
For degree two, completing the square gives cTGc=2(c0+c2/3)2+(2/3)c12+(8/45)c22. This is positive for every nonzero coefficient vector, so G is positive definite. Coordinate Euclidean length is a different metric.
G=202/302/302/302/5
03 Subtract every earlier basis direction before normalizing
Normalize 1 to q0=1/2. Because t is odd, it is perpendicular to q0; normalize it to q1=3/2t. The polynomial t2 is not perpendicular to the constant: ⟨t2,q0⟩=2/3. Subtracting this component gives w2(t)=t2−1/3.
The source loop uses range(i − 1), which skips the immediately preceding basis vector and does no subtraction for i=1. The maintained routine uses range(j) for all previous vectors with 0-based indexing. It checks the norm before division and verifies CTGC, not just the curves’ appearance.
q2(t)=845(t2−31);∫−11(t2−31)2dt=458
04 The best line for t2 is a constant, by symmetry
To project t2 onto P1=span{1,t}, use the orthonormal coordinates ⟨t2,q0⟩ and ⟨t2,q1⟩. The latter is zero because t3 is odd. The former times q0 gives the constant 1/3.
For any line a + bt, the error is the perpendicular residual t2−1/3 plus a change within P1. The integral norm obeys Pythagoras, proving global optimality. The curves need not match at individual points. This is continuous approximation, whereas 4.4 fits a finite list of measurements.
∥t2−(a+bt)∥2=458+2(a−31)2+32b2
05 A matrix projection uses the chosen metric
Let E contain coordinates of a basis for the approximation subspace. Writing the approximate coefficient vector as Eα and enforcing ETG(c−Eα)=0 gives (ETGE)α=ETGc. The metric G belongs in both places.
If the basis columns C are orthonormal for G,α=CTGc and the coefficient map is CCTG. This reduces to QQT only in a Euclidean orthonormal coordinate system. The same projection idea therefore connects all four labs without silently changing metrics.
G-weighted projection: c^=E(ETGE)−1ETGc
Check your understanding
Are sampled heights on a grid the polynomial’s coefficients?
No. Coefficients are coordinates in a basis; sampled heights are values f(tk). Sampling creates a different representation and a plain sum over samples is not automatically the integral inner product.
Why does 1 fail to be perpendicular to t2?
Their product t2 has integral 2/3 on [−1,1]. Coefficient-array orthogonality does not imply integral orthogonality.
Why must the Gram–Schmidt loop use range(j)?
At 0-based step j there are j previously accepted basis vectors, with indices 0 through j−1. range(j−1) leaves one out.
Is q2 the standard Legendre polynomial P2?
It is a normalized multiple. P2(t)=(3t2−1)/2 has P2(1)=1, while q2=5/2P2 has unit integral norm.
Does the best polynomial approximation pass through every target point?
No. It minimizes the integrated squared difference over the interval. Here the best line for t2 is 1/3, with nonzero error 8/45.
This maintained notebook uses the same notation and worked example as the web lab. Run all cells in order, then change the inputs. NumPy is required; the final plot also uses Matplotlib, available in Colab.