I'd like to fit the data in table as blow
x f(x)
3.0 2.5
4.5 1.0
7.0 2.5
9.0 0.5
when $x=5$, I want to find value of $f(x)$ by using Quadratic Spline.
this is my text book example. but there are some confused point which is I can't understand equation.
question
How to set the equation?
- $20.25a_1 + 4.5b_1 + c_1 = 1.0$
- $20.25a_2 + 4.5b_2 + c_2 = 1.0$
- $49a_2 + 7b_2 + c_2 = 2.5$
- $49a_3 + 7b_3 + c_3 = 2.5$
I meant that my question is that why does equation to be
- $a_1 + b_1 + c_1$
- $a_2 + b_2 + c_2$
- $a_2 + b_2 + c_2$
- $a_3 + b_3 + c_3$
instead of
- $a_1 + b_1 + c_1$
- $a_2 + b_2 + c_2$
- $a_3 + b_3 + c_3$
- $a_4 + b_4 + c_4$
Also
- $9a_1 + 3b_1 + c_1 =2.5$
- $81a_3+9b_3+c3 = 0.5 $
?
update2
as you can see from the picture, there is one equation 18.33
But I'm not understand it. how to that condition can be represented to 18.33 equation ? would you please give any hint?
update3.
finally, I understand almost but except the matrix.
In the text, they are use the matrix for find to each coefficients.
So My question is how to set this matrix. I can't find quite a bit relationships.
Would you please give me any hint?
Best Answer
Here is a cubic-spline interpolation for the $4$ points given in your question:
$ f(x)= \begin{cases} +0.1 \overline3(x-3.0)^3 -1.3 (x-3.0)+2.5 & \text{$3.0 \leq x \leq 4.5$}\\ -0.15\overline1(x-4.5)^3+0.6 (x-4.5)^2+0.0\overline4(x-4.5)+1.0 & \text{$4.5 \leq x \leq 7.0$}\\ +0.0 \overline8(x-7.0)^3-0.5\overline3(x-7.0)^2-0.2\overline8(x-7.0)+2.5 & \text{$7.0 \leq x \leq 9.0$}\\ \end{cases} $
Here is a piece of C code for any given number of points $(x_0,y_0),(x_1,y_1),\ldots,(x_N,y_N)$:
Here is a piece of Python code for any given number of points $(x_0,y_0),(x_1,y_1),\ldots,(x_N,y_N)$:
Please note that the two pieces of code above assume $x_0 < x_1 < \ldots < x_N$.