As a bit of a thought experiment, I wondered how hard it would be to create a cubic spline interpolation within Alteryx. As with many of my experiments BaseA rules apply.
So let’s start by reviewing how to create a cubic spline and then build it up. I chose to use the algorithm as described in Wikiversity. Specifically with type II simple boundary conditions. I’m not going through the maths but will define the steps to build the spline.
First, step is given an X array and a Y array of equal length n (greater than 2), we want to build a tridiagonal matrix which we will then solve to produce the coefficients for the piece-wise spline. The goal of the spline is that it hits every point (x, y) and that the first and second derivatives match at these points too.
Sticking with notation in the paper, lets define
H to be an
n-1 length array of the differences in
A tridiagonal matrix is a square matrix where all values except for the main diagonal and first diagonals below and above this. For example:
1 2 0 0
2 3 2 0
0 2 3 2
0 0 2 1
One advantage of a tridiagonal matrix is that they are fairly straight forward to invert and solve linear equations based on them. For the sake of coding up the algorithm - let’s define
B to be the
n length array holding the diagonal elements,
A to be the
n-1 length array of the diagonal above this and
C to be the
n-1 length array of the diagonal below:
b0 c0 0 0
a0 b1 c1 0
0 a1 b2 c2
0 0 a2 b3
#jdunkerley #tech #python
In this post, we work through building up a cubic spline from first principles first in Python, and then converting the Python code into an Alteryx macro. As a bit of a thought experiment, I wondered how hard it would be to create a cubic spline interpolation within Alteryx.