Practice polynomial interpolation and spectral methods.
Part I: Polynomial Interpolation¶
Q1: Lagrange Interpolation¶
Find the Lagrange interpolating polynomial for:
(a)
(b)
(c)
Q2: Divided Differences¶
Compute the divided difference table and Newton interpolant for .
What polynomial do you get? Is this expected?
Q3: Error Estimation¶
For interpolated at :
(a) Find the interpolating polynomial.
(b) Use the error formula to bound .
(c) Compare with the actual error.
Q4: Runge’s Phenomenon¶
Interpolate on using:
(a) equally spaced nodes
(b) equally spaced nodes
(c) equally spaced nodes
(d) Chebyshev nodes
Plot each interpolant along with . What do you observe?
Q5: Implementation¶
Implement:
(a) Lagrange interpolation
(b) Newton interpolation with divided differences
(c) Horner’s method for evaluating Newton form
Compare timings for evaluating at 1000 points with nodes.
Q6: Adding Points¶
You have the Newton interpolant for .
(a) Add the point efficiently.
(b) What is the new polynomial?
Q7: Uniqueness Proof¶
Given a set of points , show that there exists a unique polynomial of degree at most that interpolates a function at these points.
Hint: Proceed by contradiction. Assume two different interpolating polynomials exist and consider their difference . How many roots does have?
Q8: Barycentric Formula Derivation¶
This problem fills in the details of the barycentric interpolation derivation.
(a) Given the node polynomial , show that:
(b) Show that .
Hint: Use the uniqueness of polynomial interpolation—what function do the Lagrange polynomials interpolate when all data values are 1?
Q9: Chebyshev Polynomials¶
The Chebyshev polynomials are defined as where and .
(a) Show that for an appropriate choice of .
(b) Compute , , , and explicitly as polynomials in .
(c) Write as a sum of Chebyshev polynomials.
(d) Prove the recurrence relation: .
Q10: Quadrature Comparison¶
Consider the integral . The exact value is:
(a) Implement the trapezoidal rule with equispaced points.
(b) Implement Chebyshev quadrature (Clenshaw-Curtis) with Chebyshev points.
(c) For with , compute the absolute error for both methods. Plot on a log-log scale. What convergence rates do you observe?
(d) Repeat for the Gaussian integral:
with . How do the methods compare for this smooth function?
Part II: Spectral Differentiation¶
Q11: Chebyshev Differentiation Matrix¶
(a) Implement the Chebyshev differentiation matrix for points.
(b) Verify that (derivative of constant is zero).
(c) For , compute and compare to exact .
Q12: Spectral vs. Finite Difference¶
For on :
(a) Compute the derivative using a 2nd-order centered finite difference.
(b) Compute the derivative using the Chebyshev differentiation matrix.
(c) Plot max error vs. for both methods on a semilog plot.
(d) How many points does each method need for 10 digits of accuracy?
Q13: Differentiation Matrix Properties¶
Consider the function on .
(a) Implement the Chebyshev differentiation matrix construction.
(b) Compute the derivative at the Chebyshev points using .
(c) Compare with the exact derivative at the same points.
(d) Implement a second-order finite difference approximation on an equispaced grid with the same number of points. Compare the errors.
Part III: Spectral Methods for BVPs¶
Q14: Simple BVP¶
Solve on with .
(a) Find the exact solution.
(b) Implement spectral collocation.
(c) Plot error vs. . Is convergence exponential?
Q15: Variable Coefficient BVP¶
Solve on with and .
(a) Set up the spectral collocation system.
(b) Solve for .
(c) How can you assess convergence when you don’t know the exact solution?
Q16: Neumann Boundary Conditions¶
Solve on with and .
(a) Modify the spectral collocation setup for mixed boundary conditions.
(b) Solve and compare to the exact solution.
(c) What changes if both conditions are Neumann? Is the problem well-posed?
Q17: Eigenvalue Problem¶
For the Laplacian eigenvalue problem on with :
(a) The exact eigenvalues are . Compute them spectrally.
(b) Plot the error in the first 10 eigenvalues vs. .
(c) Why are higher eigenvalues less accurate?
Q18: Helmholtz Equation¶
Solve on with , where and .
(a) Solve using spectral collocation.
(b) What happens as approaches an eigenvalue of ?
(c) How many points are needed for a given accuracy as increases?
Q19: Comparison with scipy.solve_bvp¶
Use scipy.integrate.solve_bvp to solve:
(a) Solve using
solve_bvp(finite difference based).(b) Solve using spectral collocation (need Newton iteration for nonlinear!).
(c) Compare accuracy and number of points needed.
Q20: Fourth-Order Problem¶
Solve the beam equation on with clamped boundary conditions: .
(a) Form .
(b) How do you impose 4 boundary conditions?
(c) Solve and compare to the exact solution.
Q21: Periodic Problem with Fourier¶
Solve on with periodic boundary conditions.
(a) Use FFT-based differentiation instead of Chebyshev.
(b) Compare to the exact solution.
(c) Why is Fourier better than Chebyshev for periodic problems?
Self-Assessment Questions¶
Test your understanding with these conceptual questions:
Polynomial Interpolation¶
Uniqueness: If you have 4 data points, what is the maximum degree of the interpolating polynomial?
Lagrange: What is ? What is ?
Error: Why does the interpolation error formula look similar to Taylor’s theorem error?
Runge: Why do equally spaced nodes cause problems for some functions?
Barycentric: Why is the second barycentric formula “scale invariant”? Why does this matter numerically?
Chebyshev: Why do Chebyshev points cluster near the endpoints of ?
Coefficient Decay: If a function has a jump discontinuity, what decay rate do you expect for its Chebyshev coefficients?
Gibbs: Does increasing the polynomial degree eliminate the overshoot near a discontinuity? Why or why not?
Spectral Methods¶
Differentiation Matrix: Why is the Chebyshev differentiation matrix dense while finite difference matrices are sparse?
Accuracy: Why do spectral methods achieve exponential convergence for smooth problems?
Boundary Conditions: How do you modify the spectral system to impose Dirichlet vs. Neumann boundary conditions?
Eigenvalues: Why are the high-frequency eigenvalues of less accurate than low-frequency ones?
Limitations: When would you choose finite differences over spectral methods?
Grid Points: Why do Chebyshev points cluster near the boundaries?
Periodic vs. Non-periodic: When should you use Fourier methods vs. Chebyshev methods?