Results 1 to 8 of 8

Thread: How does one use Cubic Spline Interpolation?

  1. #1
    Junior Member
    Joined
    Mar 2008
    Posts
    31

    How does one use Cubic Spline Interpolation?

    Hello all, I would like to know how cubic spline interpolation is used to create a smooth curve given a set of data points. This is the method used by a lot of software when the user wants to generate a function from a set of data points. I know the method involves the value of the second derivative being equated to 0 between points but not much else, please can someone explain?
    Follow Math Help Forum on Facebook and Google+

  2. #2
    MHF Contributor arbolis's Avatar
    Joined
    Apr 2008
    From
    Teyateyaneng
    Posts
    1,000
    Awards
    1
    Say you have 20 points, $\displaystyle x_0$, $\displaystyle x_1$, to $\displaystyle x_{19}$. And you know the value of a function f only in these points. Cubic splines are used to approximate the function f (from which you don't know the formula, or its value everywhere) between each intervals $\displaystyle [x_0,x_1]$, $\displaystyle [x_1,x_2]$, etc. The approximation is made by cubic polynomials on each interval.
    You said :
    I know the method involves the value of the second derivative being equated to 0 between points
    . This is not always true, but when it happens, we call it a natural cubic spline. It is made because if we don't use this condition, then we cannot find the cubic spline (because it has too much unknowns. In order to determine it, we add 2 conditions : its second derivative is equals to 0 at $\displaystyle x_0$ and at $\displaystyle x_n$, or in our case $\displaystyle x_{19}$.)
    The cubic spline must satisfy some other conditions, for example it must be continuous and its order must equals to 3 (in our case).
    Maybe I can look if I can give you an example (just ask me if you would like to).
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Junior Member
    Joined
    Mar 2008
    Posts
    31

    Thanks

    Thanks for that, it sounds very interesting! Now that I know the difference between cubic splines and natural cubic splines, I will try to learn how to use cubic splines first.

    Maybe I can look if I can give you an example (just ask me if you would like to).
    Yes please that'd be fantastic! Can you please explain how to perform the operation mathematically.
    Follow Math Help Forum on Facebook and Google+

  4. #4
    MHF Contributor arbolis's Avatar
    Joined
    Apr 2008
    From
    Teyateyaneng
    Posts
    1,000
    Awards
    1
    Ok, I will give you more or less the idea.

    Let S be our cubic spline, $\displaystyle x_0=1$, $\displaystyle x_1=2$, $\displaystyle x_2=5$.
    $\displaystyle S(x)$ can be written as $\displaystyle S(x)=a_0x^3+b_0x^2+c_0x+d_0$ for all $\displaystyle x$ in $\displaystyle [1,2]$,
    $\displaystyle a_1x^3+b_1x^2+c_1x+d_1$ for all $\displaystyle x$ in $\displaystyle [2,5]$.
    We have the information that it is continuous, so looking at the nodes (the $\displaystyle x_i$s), we can write $\displaystyle a_0*2^3+b_0*2^2+2c_0+d_0=a_1*2^3+b_1*2^2+2c_1+d_1$
    We want to determine $\displaystyle a_0$, $\displaystyle b_0$, $\displaystyle c_0$, $\displaystyle d_0$ and $\displaystyle a_1$, $\displaystyle b_1$, $\displaystyle c_1$, $\displaystyle d_1$. Clearly we do not have enough information (conditions) to determine them. That's why we add the condition that $\displaystyle S''(x_0)=0$ and $\displaystyle S''(x_5)=0$.
    So deriving twice S(x), we obtain that $\displaystyle S''(x)=6a_0x+2b_0$ for all x in [1,2] and $\displaystyle S''(x)=6a_1x+2b_1$ for all x in [2,5]. I forgot to mention that the derivative of S and the second derivative of S must be continuous too, therefore we have another condition : $\displaystyle 6a_0(2)+2b_0=6a_1(2)+2b_1$. Also, we add the condition that's a natural cubic spline, therefore we have $\displaystyle S''(x)=0 \Leftrightarrow 6a_1x_0+2b_1=0$ and $\displaystyle 6a_0x_2+2b_0=0$, from which you can replace $\displaystyle x_0$ and $\displaystyle x_2$ by their known values. Calculating $\displaystyle S'(x)$ and making it equals at the nodes, you obtain 2 more conditions. And that's enough to solve the problem. The problem is now to solve an 8x8 matrix. But generally you can find a nice trick and solve it fast.
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Junior Member
    Joined
    Mar 2008
    Posts
    31

    Great stuff

    This is very interesting maths, I understand what you've done so far but when you said...

    The problem is now to solve an 8x8 matrix. But generally you can find a nice trick and solve it fast.
    ... what did you mean? Are matrices the next part of finding $\displaystyle S(x)$?
    Follow Math Help Forum on Facebook and Google+

  6. #6
    MHF Contributor arbolis's Avatar
    Joined
    Apr 2008
    From
    Teyateyaneng
    Posts
    1,000
    Awards
    1
    I meant the coefficient $\displaystyle a_0$, $\displaystyle a_1$, $\displaystyle b_0$, etc. All the systems of equations we have collected till here can make an 8x8 matrix. You are not obligated to use matrices, but you need to solve a big system of equations. There are 8 unknowns, so it's not that easy, but possible (since we have 8 conditions in total). Maybe you could try to solve the coefficients in my example, and show your work...
    Follow Math Help Forum on Facebook and Google+

  7. #7
    Junior Member
    Joined
    Mar 2008
    Posts
    31

    Hmm...

    I'm still doing Advanced Subsidary mathematics so haven't even touched matrices yet, maybe I should teach myself matrices... is it complex?
    Follow Math Help Forum on Facebook and Google+

  8. #8
    MHF Contributor arbolis's Avatar
    Joined
    Apr 2008
    From
    Teyateyaneng
    Posts
    1,000
    Awards
    1
    I'm still doing Advanced Subsidary mathematics so haven't even touched matrices yet, maybe I should teach myself matrices... is it complex?
    All depends on what you are looking for. In our example, we just need to reduce an $\displaystyle 8$x$\displaystyle 8$ matrix, or equivalently, solve a system of 8 equations involving 8 unknowns. The "matrix theory" needed for that is very basic (the 3 basics operations to get the reduced matrix). I suggest you not to study matrices only for this purpose. Don't forget that you still can find $\displaystyle a_0$ and the $\displaystyle 7$ other unknowns without passing by matrices. Having found the 8 unknowns, you found the natural cubic spline that pass through the 3 given points.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Replies: 0
    Last Post: Nov 28th 2010, 12:54 PM
  2. [SOLVED] Cubic Spline URGENT help!
    Posted in the Differential Geometry Forum
    Replies: 1
    Last Post: Oct 24th 2010, 01:47 PM
  3. Cubic Spline
    Posted in the Advanced Math Topics Forum
    Replies: 14
    Last Post: Oct 13th 2010, 10:26 AM
  4. Cubic Spline
    Posted in the Advanced Math Topics Forum
    Replies: 8
    Last Post: Jan 29th 2010, 07:07 PM
  5. Cubic Spline Function
    Posted in the Differential Geometry Forum
    Replies: 1
    Last Post: Oct 22nd 2009, 04:31 AM

Search Tags


/mathhelpforum @mathhelpforum