1
$\begingroup$

Can someone explain to me how linear splines work and what formulas are used. I can only seem to find information on cubic splines. Which I don't really understand either

Specifically, if I were given 5 data points how would i make a linear and cubic spline?

$\endgroup$
3
$\begingroup$

You're correct that a linear spline is just a sequence of straight lines. So, in between the data points $P_{i-1} = (x_{i-1}, y_{i-1})$ and $P_{i} = (x_{i}, y_{i})$, the equation of the spline is just $$ y = \frac{x_i - x}{x_i - x_{i-1}}y_{i-1} + \frac{x - x_{i-1}}{x_i - x_{i-1}}y_{i} $$ You can easily confirm that $y(x_{i-1}) = y_{i-1}$ and $y(x_{i}) = y_{i}$, so the linear pieces join properly, with no discontinuity.

Cubic splines are covered in many places. The basic idea is to assume that each segment of the curve (between two successive data points) is a cubic polynomial, whose coefficients are to be determined. We want these cubic pieces to join smoothly; specifically, where they meet, we want their first and second derivative values to match. You write down equations that express this derivative matching. You get a system of linear equations in which the unknowns are the coefficients of the polynomial pieces. The system of equations is nicely "banded", and therefore easy to solve.

For further details, see here, or here, or this answer.

Computing cubic splines is much easier if you express each segment in Hermite form, rather than algebraic form. This ensures from the outset that values and first derivatives match, and you only have to solve a linear system that forces second derivatives to match, too. The size of your system of equations is much smaller -- you have roughly $N$ unknowns, instead of $4N$.

$\endgroup$
1
$\begingroup$

From what I've been able to understand since posting the question. If given n data points, you need to create n-1 lines to connect the points. This would give the linear spline.

For the cubic spline, it's a similar idea except you use cubic equations to create the points which gives a smoother curve. Still a little fuzzy on the details but you end up with several variable and equations for which a matrix needs to be constructed and reduced in order to solve.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.