Skip to Content

CUBIC_HERMITE_SPLINE

Overview

The CUBIC_HERMITE_SPLINE function performs piecewise cubic interpolation of a 1-D function, matching both function values and first derivatives at each data point. This method is useful for smooth curve fitting in engineering, graphics, and scientific computing, where both the value and slope of the function are known at each sample point. The interpolation is C1C^1 continuous (smooth in both value and first derivative) and is based on the Hermite form of the cubic polynomial:

H(x)=h00(t)y0+h10(t)(x1x0)dydx0+h01(t)y1+h11(t)(x1x0)dydx1H(x) = h_{00}(t) y_0 + h_{10}(t) (x_1 - x_0) dydx_0 + h_{01}(t) y_1 + h_{11}(t) (x_1 - x_0) dydx_1

where h00h_{00}, h10h_{10}, h01h_{01}, and h11h_{11} are Hermite basis functions, y0y_0, y1y_1 are function values, and dydx0dydx_0, dydx1dydx_1 are derivatives at the endpoints of each interval. For more details, see the SciPy CubicHermiteSpline documentation and the Wikipedia article.

This function is a simplified wrapper for the SciPy CubicHermiteSpline class, supporting only 1D arrays and not exposing advanced options like axis or extrapolate.

This example function is provided as-is without any representation of accuracy.

Usage

To use the function in Excel:

=CUBIC_HERMITE_SPLINE(x, y, dydx, x_new)
  • x (2D list, required): Table of one column, strictly increasing x-coordinates of data points.
  • y (2D list, required): Table of one column, function values at each x.
  • dydx (2D list, required): Table of one column, first derivatives at each x.
  • x_new (2D list, required): Table of one column, x-coordinates where interpolation is desired.

The function returns a 2D list (column vector) of interpolated values at each x_new, or an error message (list of one string) if the input is invalid.

Examples

Example 1: Interpolate a Sine Curve

Inputs:

xydydxx_new
00.01.00.5
10.841470.54030.75
20.909297-0.41611.5
30.14112-0.989992.5

Excel formula:

=CUBIC_HERMITE_SPLINE({0;1;2;3}, {0;0.84147;0.909297;0.14112}, {1;0.5403;-0.4161;-0.98999}, {0.5;0.75;1.5;2.5})

Expected output:

Result
0.4782
0.6809
0.9949
0.5969

Example 2: Linear Data

Inputs:

xydydxx_new
0010.5
1111.5
2212.0

Excel formula:

=CUBIC_HERMITE_SPLINE({0;1;2}, {0;1;2}, {1;1;1}, {0.5;1.5;2.0})

Expected output:

Result
0.5
1.5
2.0

Example 3: Quadratic Data

Inputs:

xydydxx_new
0000.5
1121.5
2442.0

Excel formula:

=CUBIC_HERMITE_SPLINE({0;1;2}, {0;1;4}, {0;2;4}, {0.5;1.5;2.0})

Expected output:

Result
0.25
2.25
4.0

Example 4: Flat Data

Inputs:

xydydxx_new
0200.5
1201.0
2201.5

Excel formula:

=CUBIC_HERMITE_SPLINE({0;1;2}, {2;2;2}, {0;0;0}, {0.5;1.0;1.5})

Expected output:

Result
2.0
2.0
2.0

Python Code

from scipy.interpolate import CubicHermiteSpline as scipy_cubic_hermite_spline def cubic_hermite_spline(x, y, dydx, x_new): """ Piecewise cubic interpolation matching values and first derivatives at each point. Args: x: 2D list, strictly increasing x-coordinates of data points. y: 2D list, function values at each x. dydx: 2D list, first derivatives at each x. x_new: 2D list, x-coordinates where interpolation is desired. Returns: 2D list (column vector) of interpolated values at each x_new, or a list of one string error message if input is invalid. This example function is provided as-is without any representation of accuracy. """ # Validate input shapes try: x_flat = [float(row[0]) for row in x] y_flat = [float(row[0]) for row in y] dydx_flat = [float(row[0]) for row in dydx] x_new_flat = [float(row[0]) for row in x_new] except Exception: return [["Invalid input: all arguments must be 2D lists of numbers."]] if not (len(x_flat) == len(y_flat) == len(dydx_flat)): return [["Invalid input: x, y, dydx must have the same length."]] if len(x_flat) < 2: return [["Invalid input: at least two data points required."]] if any(x2 <= x1 for x1, x2 in zip(x_flat, x_flat[1:])): return [["Invalid input: x must be strictly increasing."]] try: spline = scipy_cubic_hermite_spline(x_flat, y_flat, dydx_flat) y_new = spline(x_new_flat) return [[round(float(val), 4)] for val in y_new] except Exception as e: return [[f"scipy.interpolate.CubicHermiteSpline error: {e}"]]

Live Notebook

Edit this function in a live notebook.

Live Demo

Last updated on