We demonstrate a symbolic/ numeric parameter study by an interpolation example to introduce the SymPy command lambdify.
Let's consider the task to interpolate the data and . Here, is a free parameter, which we will vary over the interval.
The quadratic interpolation polynomial has coefficients depending on this parameter:
Using SymPy and the monomial approach described in Exercise 3 in Section 4.11: Exercises gives us the closed formula for these coefficients:
t=symbols('t')
x=[0,t,1]
# The Vandermonde Matrix
V = Matrix([[0, 0, 1], [t**2, t, 1], [1, 1,1]])
y = Matrix([0,1,-1]) # the data vector
a = simplify(V.LUsolve(y)) # the coefficients
# the leading coefficient as a function of the parameter
a2 = Lambda(t,a[0])
We obtain a symbolic function for the leading coefficient of the interpolation polynomial:
Now it is time to turn the expression into a numeric function...