# Placement of variables in setting up a cubic spline matrix

I have to go through a math modeling process in my textbook and re-create it using different data. I can solve most of the problems, but then I get to finding an empirical cubic spline model. The data given is:

$$\begin{array}{c|ccccccccccc}x & 0 & 0.01 & 0.03 & 0.08 & 0.2 & 0.4 & 0.67 & 0.85 & 0.93 & 0.97 & 1.0\\ q & 1000 & 1050 & 1150 & 1250 & 1350 & 1450 & 1550 & 1650 & 1750 & 1850 & 2000\\ \end{array}$$

This results in the following cubic splines: $$\begin{array}{cc} Data Range & Cubic Spline\\ 0 \leq x \lt 0.01 & S_1(x) = 1000 + 4924.92x + 750788.75x^3\\ 0.01 \leq x \lt 0.03 & S_2(x) = 1050 + 5150.18(x - 0.01) + 22523.66(x - 0.01)^2 - 1501630.8(x - 0.01)^3\\ 0.03 \leq x \lt 0.08 & S_3(x) = 1150 + 4249.17(x - 0.03) - 67574.14(x - 0.03)^2 + 451815.88(x - 0.03)^3\\ 0.08 \leq x \lt 0.20 & S_4(x) = 1250 + 880.37(x - 0.08) + 198.24(x - 0.08)^2 - 4918.74(x - 0.08)^3\\ 0.20 \leq x \lt 0.40 & S_5(x) = 1350 + 715.46(x - 0.20) - 1572.51(x - 0.20)^2 + 2475.98(x - 0.20)^3\\ 0.40 \leq x \lt 0.67 & S_6(x) = 1450 + 383.58(x - 0.40) - 86.92(x - 0.40)^2 + 140.80(x - 0.40)^3\\ 0.67 \leq x \lt 0.85 & S_7(x) = 1550 + 367.43(x - 0.67) + 27.12(x - 0.67)^2 + 5655.69(x - 0.67)^3\\ 0.85 \leq x \lt 0.93 & S_8(x) = 1650 + 926.92(x - 0.85) + 3081.19(x - 0.85)^2 + 11965.43(x - 0.85)^3\\ 0.93 \leq x \lt 0.97 & S_9(x) = 1750 + 1649.66(x - 0.93) + 5952.90(x - 0.93)^2 - 382645.25(x - 0.93)^3\\ 0.97 \leq x \lt 1.00 & S_{10}(x) = 1850 + 3962.58(x - 0.97) + 51870.29(x - 0.97)^2 - 576334.88(x - 0.97)^3\\ \end{array}$$

I know you have to set up a tridiagonal matrix using q$_i, x_i$, and h$_i (x_i - x_{i-1}$) and solve the matrix for y''$_i$. From there, you use four equations to solve for the coefficients of each power of cublc splines S$_i$. However, when I set up the matrix, I don't have enough to solve for each variable - I end up with free variables, which should not happen. I must be putting the numbers somewhere wrong, but I can't figure it out. I know the tridiagonal matrix is set up as follows:

Where y$_n$ means q$_i$ and h$_n$ means h$_i$. I don't know what the ending conditions are (the example this comes from doesn't say). Can someone show me how to determine how to determine the unknown values corresponding to the ending conditions so I can understand how to solve other cubic spline problems? Thanks.

-
There are several different kinds of cubic spline ("natural", "parabolic runout", etc.). The way in which they differ is precisely in the question of what goes in those missing slots in your matrix. Somewhere in the text it ought to tell you what kind of runout they want you to use and what the corresponding thing is to put in those missing slots. –  Gerry Myerson Mar 4 '12 at 0:56
Right. Added. I am using a natural cubic spline - but the problem I have is that I set up the matrix but don't have enough rows to solve the matrix –  SSumner Mar 4 '12 at 23:23
If the second derivative at each endpoint is zero, doesn't that mean you have only n-2 unknowns, namely, y_2'',...,y_{n-1}''? So all your matrices and vectors are a little bit smaller than what you have written, right? –  Gerry Myerson Mar 5 '12 at 0:43
Right, but somehow the example given came up with 10 equations, and I don't know how they did that since I can only seem to come up with 8. –  SSumner Mar 5 '12 at 1:26
I'm not following. The example you've posted has 11 data points. That implies 9 unknown values of the 2nd derivative. You should have a system of 9 equations in these 9 unknowns. Then the formulas should yield 10 cubics, one for each interval bounded by two consecutive data points. Which of these numbers are you not getting? –  Gerry Myerson Mar 5 '12 at 1:53
show 3 more comments