A Vandermonde matrix turns polynomial interpolation into a linear-system problem. For each point (xᵢ, yᵢ), it records the powers of xᵢ so solving for the coefficient vector produces a polynomial passing through the data. section 6.3.1
For N points and a polynomial of degree N−1:
- Build an N×N matrix whose row i contains 1, xᵢ, xᵢ², through xᵢⁿ⁻¹. section 6.3.1
- Place the observed y values in a column vector and solve Vandermonde × coefficients = y values. section 6.3.5
- Use exactly N equations for N coefficients; fewer points leave a continuum of possible polynomials. section 6.3.1
Interpolating five measured values
For xs = [1, 2, 3, 4, 5] and ys = [4, 2, 3, 2, 4], construct the matrix with Python list comprehensions, convert it and ys to SymPy matrices, then solve for a₀ through a₄. The resulting coefficients define the degree-four interpolating polynomial. section 6.3.5
Listing 6.2 Computing the interpolating polynomial
Vandermonde = Matrix([[xs[i]**j for j in range(N)] for i in range(N)]) #1
Ys = Matrix(ys) #2
a0, a1, a2, a3, a4 = symbols('a0 a1 a2 a3 a4')
Pol = Matrix([a0, a1, a2, a3, a4]) #3
solution = solve(Vandermonde*Pol - Ys, (a0, a1, a2, a3, a4)) #4
a = [value for key, value in solution.items()] #5
The executable listing shows matrix construction, vector conversion, symbolic coefficient setup, linear-system solving, and coefficient extraction. section 6.3.5
