How to Apply Cubic Spline Interpolation in Excel

This guide will explain how to apply cubic spline interpolation in Excel to draw a smooth curve that goes through a series of given points.

Cubic spline interpolation is a method in mathematics that allows you to define a smooth curve that passes through all given data points. This is done by creating cubic polynomial equations between each pair of adjacent data points.

sample output of cubic spline interpolation in Excel

This method creates equations that show a smooth curve between points. Hence why it is often used in 3D rendering and animation to generate smooth objects and motion paths. 

Other than that, this is widely used in the data analysis field as it captures the overall trend of a dataset by smoothing out irregularities caused by missing data or errors.

While Excel does not have a built-in cubic spline interpolation function, we can define our own custom function to generate an interpolated curve from our data.

In this guide, we will provide a step-by-step tutorial on how to apply cubic spline interpolation in Excel.

 

A Real Example of Applying Cubic Spline Interpolation

Let’s explore a simple example where we can apply cubic spline interpolation on a limited set of data points.

sample input datapoints

In the image above, we are given five data points (x-y ordered pairs) as input. Using these data points, we want to plot a smooth curve that passes through each point.

use scatterplot chart to visualize points

We’ll use a scatterplot graph to visualize our data points in a Cartesian plane. 

Since Excel does not have built-in support for cubic spline interpolation, we’ll need to add the functionality using VBA code. You can access this Google Drive link to see the VBA code used in our worksheet.

After adding the custom code as a new module in our worksheet, we’ll now have access to the custom CUBICSPLINE function:

=CUBICSPLINE($A$3:$A$7,$B$3:$B$7,$C$3:$C$21)

The formula requires three arrays as input: the array of input x-values, the array of input y-values, and the array of output x-values.

cubic spline interpolation in Excel

We can use Excel’s Chart feature to create a scatter plot chart that will visualize both the input data points and the resulting output of our cubic spline interpolation.

use scatterplot

To plot our smooth curve, we can create a new series of data points using cubic spline interpolation on our original set of points. We’ll add equally-spaced points at an interval of 0.5 between x=0 and x=9 and use an algorithm to determine the appropriate y-value.

add scatterplot chart

In our final result, we can see that the yellow curve smoothly passes through all our data points. Each dot within the yellow line is a data point generated by a custom cubic spline interpolation function.

visualize output of cubic spline interpolation in Excel

Create your own copy of our example by clicking on the link below.

Head to the next section to read our step-by-step tutorial on how to create a weighted sales pipeline.

 

How to Apply Cubic Spline Interpolation in Excel

  1. To use the custom function for cubic spline interpolation, we must be able to access the Developer tab. If you can’t find the Developer tab, you can enable it through the Excel options dialog box. Click on the Options button in the File tab to view the dialog box seen below.
    add developer tabHead to the Customize Ribbon options and check the Developer option under the list of main tabs to display. Click on OK to apply these changes.
  2. Next, head to the Developer tab and click on the Visual Basic option.
    access Visual Basic editor
  3. A Visual Basic editor will appear in a new window. Click on Insert > Module to add a new module to our current worksheet.
    to apply cubic spline interpolation in Excel, we'll need to add a new module
  4. Paste our custom code into the provided text editor.
    custom VBA code will define function to use for cubic spline interpolation in excelClick on the Save icon to save the module to our project.
    click Save icon
  5. Head back to the main worksheet and prepare the data needed for cubic spline interpolation. We’ll need the x-values and y-values of each input data point (shown below in columns A and B). We must also provide a range of x-values to use for creating our curve (shown below in column C).
    set up input data and outpu x valuesWe’ll use the CUBICSPLINE function from our VBA module to apply cubic spline interpolation on our original data points.
    use cubicspline function to use cubic spline interpolation in ExcelIn the image above, we’ve added the formula =CubicSpline($A$3:$A$7,$B$3:$B$7,$C$3:$C$21) to generate the y-values for our smooth curve.
  6. Hit the Enter key to evaluate the CUBICSPLINE function. The function will output an array of corresponding y-values for each x-value given in the third argument.
    hit the Enter key
  7. Select the range of x-values and interpolated y-values that we’ll need to plot our curve.
    select x-y values of output
  8. In the Insert menu, click on the Scatter icon and click on the scatter chart option with smooth lines and markers.
    add scatter chart
  9. The resulting scatter chart will plot the result of our cubic spline interpolation.
    scatter chart of cubic spline interpolation in Excel
  10. We can add another series to highlight the input data points. To do this, click on Chart Design > Select Data.
    select data menu
  11. In the Select Data Source dialog box, click on the Add button.
    add new data sourceEnter the ranges that include the x-values and y-values of our input data points. Click on OK to proceed.
    enter ranges of original data pointsThe scatter chart should now show the data points used to fit our spline curve.
    cubic spline interpolation in Excel with original datapoints

That should be everything you need to know to apply cubic spline interpolation on a series of points.

If you want to read more about finding curves that fit existing data, read our guide on how to perform cubic regression in Excel.

That’s all for this guide! You can browse through our library of spreadsheet resources, tips, and tricks to learn even more about Excel.

Get emails from us about Excel.

Our goal this year is to create lots of rich, bite-sized tutorials for Excel users like you. If you liked this one, you'd love what we are working on! Readers receive early access to new content.

7 Shares:
Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like