SciPy Cubic Splines
Choose boundary conditions as part of the interpolation model.
How it works
A cubic spline joins polynomial pieces with smoothness constraints. Boundary conditions determine additional behaviour and can change the interior result. Use conditions that are supported by the problem rather than selecting a named option merely because it looks smooth. This exact cubic fixture supplies endpoint derivatives from the known formula, making the interpolation and derivative checks independent.
Run the code
The complete source is checked locally and in the existing SciPy browser editor. Select Try in playground to preload it, then choose Run. Preloading does not execute the program. The browser starts an isolated runtime and does not read your personal PC files.
The reviewed local environment is Python 3.12.14, NumPy 2.5.4 and SciPy 1.18.0. The browser uses Pyodide 0.27.7, NumPy 2.0.2 and SciPy 1.14.1. Use a separate virtual environment for local work, then run python cubic-splines.py. Apache, MySQL and PHP are not required. Environment setup.
Example
import numpy as np
import scipy
from scipy.interpolate import CubicSpline
x = np.array([0., 1., 2., 3.])
y = x ** 3
curve = CubicSpline(x, y, bc_type=((1, 0.), (1, 27.)), extrapolate=False)
assert abs(float(curve(1.5)) - 3.375) < 1e-10
assert abs(float(curve(1.5, 1)) - 6.75) < 1e-10
print(f"Midpoint value: {float(curve(1.5)):.6f}")
Expected result
Midpoint value: 3.375000
The derivative of x cubed is three x squared, giving zero and twenty-seven at the endpoints. The midpoint value is 1.5 cubed. Real measurements may not justify exact derivative conditions, so document where those conditions come from.
For precise contracts and version differences use the official SciPy documentation. Synthetic fixtures do not establish real instrument accuracy or population conclusions.