HomeNumerical Math -> Cubic Spline Interpolation



Sage Pages

YouTubes (Macedonian)
coming soon...

Important SAGE syntax notes:

There are many methods to create cubic splines, but because it is interpolation all plots must pass through the given points!

#1 Sage lists (1xn) are always floating regardless of whether the input values are integers! NumPy arrays look at the input so don't forget to declare the dtype!

  • Natural Cubic Splines create a separate cubic function between each set of 2 successive points (every point is a knot). See first two examples above.
    • The solution of natural cubic splines requires defining several functions, but is (a) reusable and (b) cheap (fast) since the arrays are all lists (1xn)
    • Note: The coefficients k are the curvatures (second derivatives). We use the formulas to get the coefficients of the cubic polynomials at the points (see link below).
  • Other Cubic Splines - we solve two problems where the middle point is the only know (i.e. we find two cubic functions). See the second two examples above.
    • The problems are "set up" with conditions so that this requires the solving of AX=B where A is an 8x8 matrix. The solution is much easier to create, but (a) not must be created for each problem separately and (b) costs more computer time to solve.
    • We say "matrix" but we are either using sage lists (1x8) or numpy arrays (8x8). We are NOT using python matrices.
    • Here AX=B is a square matrix equation, so assuming the conditions are good (they are) so that the equation is good (A is non-singular), then we can just use "left-division" A\B to get our solution.
    • Note: the coefficients of the polynomials are at x and NOT at the points! (We need to use Taylor Polynomials to get the coefficients at the points.)

References:

  1. Cubic Splines Tutorial
  2. TriDiagonal Matrix Algorithms (LUdecomp3 and LUsolve3)
  3. Natural Spline Coefficient Formulas
  4. Kiusalaas, J. (2010) Numerical Methods in Engineering with Python. Cambridge University Press, UK.