Results 1 to 12 of 12

Math Help - Numerical Analysis- Cubic Spline?

  1. #1
    Member
    Joined
    Feb 2010
    Posts
    146

    Numerical Analysis- Cubic Spline?

    In my numerical analysis class i was sick during the class they did the Cubic Spline and I'm getting confused.

    Question: Determine the FREE cubic spline S that interpolates the data f(0)=0, f(1)=1 and f(2)=2.

    So far from following the examples in the book i have:

    S(x)={S_0(x)=a_0+b_o(x-0)+c_0(x-0)^2+d_0(x-0)^3 0<=x<=1
    {S_1(x)=a_1+b_1(x-1)+c_1(x-1)^2+d_1(x-1)^3 1<=x<=2

    Like i said I was following an example in the book and its not very clear so I'm not even sure how i got that far. I know i have to form a matrix but I have no clue how...the answer in the back of the books says : S(x)=x on [0,2]

    If someone can please help maybe to explain the steps and then I could follow suit. And i'm pretty sure it belongs in this category if not please redirect me. Thanks so much.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Senior Member
    Joined
    Mar 2009
    Posts
    378
    A Free Cubic Spline is also called a Natural Cubic Spline.
    First, let's define a set of data with x-coordinates x_0,\dots, x_n and corresponding y-values [tex]y_0,\dots,y_n[tex]. To determine cubic splines we must have a closed system. To close the system we could choose various conditions. For a natural spline we choose the boundary conditions S''(x_0) = S''(x_n) = 0. For your example this implies S''(0) = S''(2) = 0. Let's define the cubic spline on the i-th interval [x_i,x_{i+1}]by
    S_i(x) = \dfrac{z_i}{6h_i}(x_{i+1} - x)^3 + \dfrac{z_{i+1}}{6h_i}(x - x_i)^3 + C(x - x_i) + D(x_{i+1} - x).
    Then we can define a system of equations
    \begin{bmatrix}u_1 & h_1 \\<br />
h_1 & u_2 & h_2 \\<br />
&  h_2 & u_3 & h_3 \\<br />
& & \ddots & \ddots & \ddots \\<br />
& & & h_{n-3} & u_{n-2} & h_{n-2} \\<br />
& & & & h_{n-2} & u_{n-1}\end{bmatrix}<br />
\begin{bmatrix} z_1 \\ z_2 \\ z_3 \\ \vdots \\ z_{n-2} \\ z_{n-1}\end{bmatrix} =<br />
\begin{bmatrix} v_1 \\ v_2 \\ v_3 \\ \vdots \\ v_{n-2} \\ v_{n-1}\end{bmatrix}<br />
    where
    \begin{matrix} h_i=x_{i+1} - x_i \\ u_i = 2(h_i + h_{i-1}) \\ b_i = \dfrac{6}{h_i}(y_{i+1} - y_i) \\ v_i = b_i - b_{i-1}\end{matrix}.
    Additionally, since this is a Natural Spline we see that z_0 = z_n = 0 and C = \dfrac{y_{i+1}}{h_i} - \dfrac{z_{i+1}h_i}{6},\; D = \dfrac{y_i}{h_i} - \dfrac{z_ih_i}{6}.
    So in the end finding the cubic spline involves solving the system that I posted. All you have to do is plug things in.

    I would say this belongs in the Advanced Applied Mathematics section.
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Member
    Joined
    Feb 2010
    Posts
    146
    "All you have to do is plug things in." <- would it be a stupid question to ask where x_i and x_i+1 are taken from? I know you said the interval but in my example there was no interval unless its from [0,2]. your explanation is a little more indepth than my book, however following my book, I got confused as to what my x_i and stuff if. Otherwise I understand the actual process.
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Senior Member
    Joined
    Mar 2009
    Posts
    378
    Based on your data there is a partition of the interval [x_0=0,x_2=2] into subintervals [x_0=0,x_1=1] and [x_1=1,x_2=2]. The corresponding y-values are y_0 = 0, y_1 = 1, y_2 = 2.

    EDIT: Splines are defined on intervals. In your case there will be a spline function S_0(x) defined on the interval [0,1] and another spline function S_1(x) defined on the interval [1,2].
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Member
    Joined
    Feb 2010
    Posts
    146
    Wait, in my example i have S_0(x) and S_1(x)..am I doing this twice because i have f(0)=0 f(1)=1 and f(2)=2. so my interval would go from [0,2] but I have to split it up from [0,1] and [1,2]? Sorry i'm just trying to figure things out.
    Follow Math Help Forum on Facebook and Google+

  6. #6
    Member
    Joined
    Feb 2010
    Posts
    146
    Quote Originally Posted by lvleph View Post
    Based on your data there is a partition of the interval [x_0=0,x_2=2] into subintervals [x_0=0,x_1=1] and [x_1=1,x_2=2]. The corresponding y-values are y_0 = 0, y_1 = 1, y_2 = 2.

    EDIT: Splines are defined on intervals. In your case there will be a spline function S_0(x) defined on the interval [0,1] and another spline function S_1(x) defined on the interval [1,2].
    Haha sorry I should have waited...Thanks a bunch, at least i figured that part out
    Follow Math Help Forum on Facebook and Google+

  7. #7
    Senior Member
    Joined
    Mar 2009
    Posts
    378
    Yeah, I realized it might not have been clear, so I added.
    Follow Math Help Forum on Facebook and Google+

  8. #8
    Member
    Joined
    Feb 2010
    Posts
    146
    sorry, but I've been trying to work on matrix A, and the book shows it a little different they have [1            0          0................0<br />
                                      h_0 2(h_0+h_1)    h1  0...........0]

    etc. However my matrix was coming out like this
    [1 0 0 0 0 0 0 0                                                                            1 4 1 0 0 0 0 0 <br />
0 1 4 1 0 0 0 0 <br />
0 0 0 0 1 4 ...]

    however, the answer says this should be the matrix:
    [1 0 0 0 0 0 0 0 <br />
1 1 1 1 0 0 0 0<br />
0 0 0 0 1 0 0 0 <br />
0 0 0 0 1 1 1 1 <br />
0 1 2 3 0 -1 0 0 <br />
0 0 2 6 0 0 -2 0 <br />
0 0 2 0 0 0 0 0 <br />
0 0 0 0 0 0 2 6]

    I don't know why mine isn't coming out the same as the other one. What am i doing wrong? Is it possible to input the numbers in eg: (h_0= 1-0) <-if i even did that right.
    Follow Math Help Forum on Facebook and Google+

  9. #9
    Member
    Joined
    Feb 2010
    Posts
    146
    Quote Originally Posted by tn11631 View Post
    sorry, but I've been trying to work on matrix A, and the book shows it a little different they have [1            0          0................0<br />
                                      h_0 2(h_0+h_1)    h1  0...........0]

    etc. However my matrix was coming out like this
    [1 0 0 0 0 0 0 0                                                                            1 4 1 0 0 0 0 0 <br />
0 1 4 1 0 0 0 0 <br />
0 0 0 0 1 4 ...]

    however, the answer says this should be the matrix:
    [1 0 0 0 0 0 0 0 <br />
1 1 1 1 0 0 0 0<br />
0 0 0 0 1 0 0 0 <br />
0 0 0 0 1 1 1 1 <br />
0 1 2 3 0 -1 0 0 <br />
0 0 2 6 0 0 -2 0 <br />
0 0 2 0 0 0 0 0 <br />
0 0 0 0 0 0 2 6]

    I don't know why mine isn't coming out the same as the other one. What am i doing wrong? Is it possible to input the numbers in eg: (h_0= 1-0) <-if i even did that right.
    sorry those should be matricies of 8x8, I'm not good with the whole adding in math symbols
    Follow Math Help Forum on Facebook and Google+

  10. #10
    Senior Member
    Joined
    Mar 2009
    Posts
    378
    Your system should be a 2x2 system.
    <br />
\begin{bmatrix}u_1 & h_1 \\<br />
h_1 & u_2<br />
\end{bmatrix}<br />
\begin{bmatrix} z_1 \\ z_2 \end{bmatrix} =<br />
\begin{bmatrix} v_1 \\ v_2 \end{bmatrix}<br />
    and z_0 = z_3 = 0.
    I have to go teach, so it will be a while if you have any other questions.

    EDIT: If you double click my equations you can see the commands for them.
    Follow Math Help Forum on Facebook and Google+

  11. #11
    Member
    Joined
    Feb 2010
    Posts
    146
    Quote Originally Posted by lvleph View Post
    Your system should be a 2x2 system.
    <br />
\begin{bmatrix}u_1 & h_1 \\<br />
h_1 & u_2<br />
\end{bmatrix}<br />
\begin{bmatrix} z_1 \\ z_2 \end{bmatrix} =<br />
\begin{bmatrix} v_1 \\ v_2 \end{bmatrix}<br />
    and z_0 = z_3 = 0.
    I have to go teach, so it will be a while if you have any other questions.
    thanks for all your help...however, the answer shows an 8x8..ugh
    Follow Math Help Forum on Facebook and Google+

  12. #12
    Senior Member
    Joined
    Mar 2009
    Posts
    378
    I was actually wrong on the size of the matrix. The matrix dimension is always 2 less than the number of data points.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. [SOLVED] Cubic Spline URGENT help!
    Posted in the Differential Geometry Forum
    Replies: 1
    Last Post: October 24th 2010, 01:47 PM
  2. Cubic Spline
    Posted in the Advanced Math Topics Forum
    Replies: 14
    Last Post: October 13th 2010, 10:26 AM
  3. Cubic Spline
    Posted in the Advanced Math Topics Forum
    Replies: 8
    Last Post: January 29th 2010, 07:07 PM
  4. Cubic Spline Function
    Posted in the Differential Geometry Forum
    Replies: 1
    Last Post: October 22nd 2009, 04:31 AM
  5. How does one use Cubic Spline Interpolation?
    Posted in the Calculus Forum
    Replies: 7
    Last Post: May 23rd 2008, 01:42 PM

Search Tags


/mathhelpforum @mathhelpforum