# Cubic Spline Interpolation partial derivative to the point

Still didn't figure out this, so looking for some help, kindly apppreciated.

By this blog https://blog.timodenk.com/cubic-spline-interpolation/index.html, the piecewise cubic spline interpolation is implemented, and the interpolated value comes out as expected, it's no problem.

The problem is, I need to calculate the partial derivatives with respect to the two nearest point $$z$$ value, for example, the interpolated point is $$(t, z)$$, and the left point is $$(t_1, z_1)$$ and the right point is $$(t_2, z_2)$$, I need to calculate $$\frac{\partial z}{\partial z_1}$$ and $$\frac{\partial z}{\partial z_2}$$, and here is my steps:

There are $$n+1$$ data points $$(t_i, z_i), for \ i = 1, 2, ..., n+1$$.

There are $$n$$ cubic polynomial equations for each interval $$[t_i, t_{i+1}], for \ i = 1, 2, ..., n$$.

$$z_i = a_i * t_i^3 + b_i * t_i^2 + c_i * t_i + d_i, for \ i = 1, 2, ..., n$$

$$z_{i+1} = a_i * t_{i+1}^3 + b_i * t_{i+1}^2 + c_i * t_{i+1} + d_i, for \ i = 1, 2, ..., n$$

also, $$z = a_i * t^3 + b_i * t^2 + c_i * t + d_i, t \in [t_i, t_{i+1}], for \ i = 1, 2, ..., n$$

By the chain rule,

$$\frac{\partial z}{\partial z_i} = \frac{\partial z}{\partial a_i} * \frac{\partial a_i}{\partial z_i} + \frac{\partial z}{\partial b_i} * \frac{\partial b_i}{\partial z_i} + \frac{\partial z}{\partial c_i} * \frac{\partial c_i}{\partial z_i} + \frac{\partial z}{\partial d_i} * \frac{\partial d_i}{\partial z_i} = t^3 / t_i^3 + t^2 / t_i^2 + t / t_i + 1$$

$$\frac{\partial z}{\partial z_{i+1}} = \frac{\partial z}{\partial a_i} * \frac{\partial a_i}{\partial z_{i+1}} + \frac{\partial z}{\partial b_i} * \frac{\partial b_i}{\partial z_{i+1}} + \frac{\partial z}{\partial c_i} * \frac{\partial c_i}{\partial z_{i+1}} + \frac{\partial z}{\partial d_i} * \frac{\partial d_i}{\partial z_{i+1}} = t^3 / t_{i+1}^3 + t^2 / t_{i+1}^2 + t / t_{i+1} + 1$$

But the result way too far from correct, compared with linear on zero interpolation, so still try to figure where goes wrong ...

As to why calculating these paritial derivatives, that's because the sensitivity can be used to calculate DV01 later, so firstly these paritial derivatives supposed to be calculated.

In solving the coefficients of a spline you are solving a collocation equation (linear systemm).

In your case you are solving the equation,

$$\mathbf{A(t) c} = \mathbf{\hat{z}} \quad \implies \quad \mathbf{c} = \mathbf{A(t)^{-1}\hat{z}}$$

where in this case, $$\mathbf{\hat{z}} = [\mathbf{z}, \mathbf{v}]$$, is a vector composed of the datasite $$z_i$$ values and some additional continuity and endpoint constraints, $$v_i$$ added into the linear system. Here $$\mathbf{c}$$ is a vector of the spline coefficients, i.e. $$[a_1, b_1, c_1, d_1, a_2, b_2, ..]$$

If you take an arbitrary t-value, $$t^*$$, this will have an associated spline value, $$z^*$$, according to:

$$z^* = \mathbf{a}(t^*)^\mathbf{T} \mathbf{c}$$

where the $$a_i$$ values depend on the value of $$t^*$$ and between which breakpoints the value lies.

The partial derivatives with respect to $$\mathbf{\hat{z}}$$ (which contains the datasites) is:

$$\frac{ \partial z^*}{\partial \mathbf{\hat{z}}} = \mathbf{a}(t^*)^\mathbf{T} \frac{\partial \mathbf{c}}{\partial\mathbf{\hat{z}} } = \mathbf{a}(t^*)^\mathbf{T} \mathbf{A(t)^{-1}}$$

• As an added comment, when applying the chain rule you have done it incorrectly when computing for example $\partial a_i / \partial z_i$. You have not accounted for the fact it is linear system with interconnected variables. It looks like you have used the formula $\partial a_i / \partial z_i = (\partial z_i / \partial a_i)^{-1}$ which is not correct in a multivariate setting.
– Attack68
Commented Mar 4 at 8:50