Typically a cubic spline is given for a set of points such that for each interval a cubic function is fitted to the points, with matching slopes and curvature, as well as the endpoints, have zero curvature (2nd derivative). This is the definition of a natural spline.
In your case, you have 4 points and 3 intervals. The number of unknowns is 12, as for each interval there are 4 unknowns (the cubic part).
Your constraints are:
- Points on given nodes (4 equations)
- Interval end points match (2 equations)
- Interval end slopes match (2 equations)
- Interval end curvature match (2 equations)
- End point cuvature zero (2 equations)
In total, you have 12 equations with 12 unknowns.
See http://www.physics.utah.edu/~detar/phys6720/handouts/cubic_spline/cubic_spline/node1.html for more details. Also wikipedia has a nice write-up.
For your case the solution is
$$ y(x)=\begin{cases}
\frac{2x(7-2x^{2})}{5} & x=0\ldots1\\
\frac{5x^{3}-27x^{2}+41x-9}{5} & x=1\ldots2\\
\frac{-x^{3}+9x^{2}-31x+39}{5} & x=2\ldots3
\end{cases} $$
Details
The general equation for a cubic spline is an interpolation using the values $Y_i$ and the 2nd derivatives $Y''_i$ at each node. Once the 2nd derivatives are known, then the spline is solved for and the following equation can be used for interpolation between nodes $i$ and $i+1$.
This is done with a parameter $t=0\ldots 1$ that spans the interval
$$\begin{aligned}
x_i & = X_i + t\,h \\
y_i & = (1-t) Y_i + y\,Y_{i+1} + \tfrac{h^2}{6} \left( (1-t) (t^2-2 t) Y''_i + t (t^2-1) Y''_{i+1} \right) \end{aligned} $$
The system of equations to find a spline is formed using the following procedure:
Start Point Either the spline in a natural spline with $Y''_1 = 0$ or it has a specified slope $Y'_1$ at which point the following equation must be used
$$ Y''_2 + 2 Y''_1 = \tfrac{6}{h^2} \left( Y_2 - Y_1 - h Y'_1 \right) \tag{i = 1}$$
Internal Points Here the slope needs to match at nodes and this is ensured with the following equation for $i=2 \ldots n-1$
$$ Y''_{i-1} + Y''_{i+1} + 4 Y''_i = \tfrac{6}{h^2} \left( Y_{i-1} + Y_{i+1} - 2 Y_i \right) \tag{i = 2 to n-1}$$
End Point Again the spline is either natural with $Y''_n = 0$ or with the specified slope $Y'_n$, and the following equation must be used.
$$ Y''_{n-1} +2 Y''_n = \tfrac{6}{h^2} \left( Y_{n-1} - Y_n + h Y'_n \right) \tag{i = n}$$
For your example, I assume you want a natural spline so only the interior points are considered, resulting in these two equations
$$\begin{aligned}
4 Y''_2 + Y''_3 & = \tfrac{6}{h^2} \left( Y_3 - 2 Y_2 + Y_1 \right) \\
Y''_2 + 4 Y''_3 & = \tfrac{6}{h^2} \left( Y_4 - 2 Y_3 + Y_1 \right)
\end{aligned}$$
Using $h=1$ and $Y=[0,2,1,0]$ and solved for $Y''_2$ and $Y''_3$.
NOTE: I have assumed constant interval with $h = X_{i}-X_{i-1}$, but that above can be adapted to a varying grid also.
In general, a b-spline curve will not pass through any of its control points.
There is an example at the bottom of this web page, which explains how repeating knot values will cause a b-spline curve to pass through one of its control points. This technique is typically used with the first and last knots, to force the spline to pass through the first and last control points.
When you repeat knots, this changes the form of the b-spline basis functions, so the ones you cited will not be correct near repeated knots.
To evaluate a cubic b-spline on the interval $[0,1]$, you need a knot sequence that has at least two knot values to the left of 0, and at least two knots to the right of 1. These 6 knots together are needed to define the basis functions that are non-zero on $[0,1]$. So, the knot vector you mentioned $(1,2,3,4, \ldots)$ certainly will not work.
If you want a b-spline curve that passes through a sequence of given points, then you need to use an "interpolating" b-spline. You compute one of these by solving a system of linear equations to get its control points, as explained by @LutzL and on this page.
Best Answer
I hope this helps.
We assume $f\in C^2([a,b])$. Since $s''(x)=s''(x_i)\frac{x_{i+1}-x}{h_i}+s''(x_{i+1})\frac{x-x_i}{h_i}$, for $x\in [x_{i},x_{i+1})$, $0\leq i\leq n-1$, it holds $$ \begin{array}{rcl} f''(x)-s''(x)&=&\left[(f''(x)-f''(x_i))+(f''(x_i)-s''(x_i))\right]\tfrac{x_{i+1}-x}{h_i}\\[0.75pc] &&+\left[(f''(x)-f''(x_{i+1}))+(f''(x_{i+1})-s''(x_{i+1})]\right)\tfrac{x-x_i}{h_i}, \end{array} $$ for $x\in [x_{i},x_{i+1})$, $0\leq i\leq n-1$. Hence, $$\parallel f''-s''\parallel_\infty\leq \omega_{h}(f'')+M_{\Delta_n},$$ being $\omega_h(f'')$ the modulus of continuity of $f''$ of size $h=\displaystyle\max_{0\leq i\leq n} x_{i+1}-x_i$ and $$M_{\Delta_n}:=\displaystyle\max_{0\leq i\leq n} |f''(x_i)-s''(x_i)|.$$ Now, let $d:=f-s\in C^2([a,b])$, with $d(x_i)=0$, $0\leq i\leq n$, and by Rolle's Theorem, $d'(\xi_{i})=0$, with $\xi_{i}\in (x_i,x_{i+1})$, $0\leq i\leq n-1$. Let $\widehat{x}, \widetilde{x}\in [a,b]$ such that $\parallel d \parallel_\infty=|d(\widehat{x})|$ and $\parallel d' \parallel_\infty=|d'(\widetilde{x})|$, respectively. There exist indexes $i,j$ such that $|\widehat{x}-x_i|\leq \frac{h}{2}$ and $|\widetilde{x}-\xi_j|\leq h$. Then $$ \parallel d \parallel_\infty=|d(\widehat{x})|=\left| \int_{x_i}^{\widehat{x}} d'(x)dx\right|\leq \tfrac{h}{2} \parallel d' \parallel_\infty, \quad \parallel d'\parallel_\infty =|d'(\widetilde{x})|=\left| \int_{\xi_j}^{\widetilde{x}} d''(x)dx\right|\leq h\parallel d''\parallel_\infty. $$
It remains to study the size of $M_{\Delta_n}$. For the natural and the complete cubic splines (even for the periodic one if $f$ extends periodically to a $C^2$ function on $\mathbb{R}$), it holds $$ \begin{array}{rcl} \widehat{\delta}_i&:=&\tfrac{h_{i-1}}{6(h_{i-1}+h_i)}f''(x_{i-1})+\frac{1}{3}f''(x_i)+\tfrac{h_i}{6(h_{i-1}+h_i)}f''(x_{i+1})-f[x_{i-1},x_i,x_{i+1}] \\[0.75pc] &&\tfrac{h_{i-1}}{6(h_{i-1}+h_i)}f''(x_{i-1})+\frac{1}{3}f''(x_i)+\tfrac{h_i}{6(h_{i-1}+h_i)}f''(x_{i+1})-\tfrac{f''(\widehat{\zeta}_i)}{2},\quad \widehat{\zeta}_i\in[x_{i-1},x_{i+1}], \\[0.75pc] &&\tfrac{h_{i-1}}{6(h_{i-1}+h_i)}(f''(x_{i-1})-f''(\widehat{\zeta}_i))+\frac{1}{3}(f''(x_i)-f''(\widehat{\zeta}_i))+\tfrac{h_i}{6(h_{i-1}+h_i)}(f''(x_{i+1})-f''(\widehat{\zeta}_i)), \end{array} $$ and $|\widehat{\delta}_i|\leq \frac{1}{6}\omega_{2h}(f'')+\frac{1}{3}\omega_{h}(f'')\leq \frac{2}{3}\omega_{h}(f'')$, $0\leq i\leq n$ (with the convention, $h_{-1}:=0$, $x_{-1}:=x_0$, for $i=0$; for $i=n$, $h_n:=0$, $x_{n+1}=x_n$ in case of the complete spline, and $h_n:=h_0$, $x_{n+1}=x_n+h_n$, with $f(x_{n+1}):=f(x_1)$, for the periodic one).
If $AM=b$ denotes the linear system for the spline momenta ($s''(x_i)$) and $F''$ is the corresponding vector of second derivatives of $f$ at the grid points, then $A(F''-M)=AF''-b=\widehat{\delta}$, where $\widehat{\delta}$ is the corresponding vector with coefficients $\widehat{\delta}_i$. Since $\parallel A^{-1}\parallel_\infty \leq \frac{1}{1-\parallel I-A\parallel_\infty}=\frac{1}{1-\frac{5}{6}}=6$, this gives $$ M_{\Delta_n}=\parallel F''-M \parallel_\infty\leq \parallel A^{-1} \parallel_\infty \parallel\widehat{\delta} \parallel_\infty\leq 4\omega_{h}(f''). $$
This gives $\parallel f^{(j)}-s^{(j)} \parallel_\infty=o(h^{2-j})$, $j=0,1,2$ for the three splines above considered. If $f$ does not extend to a $C^2$ periodic function, then the above argument only gives for the periodic spline $\parallel f^{(j)}-s^{(j)} \parallel_\infty=\mathcal{O}(h^{2-j}/h_{\rm min})$, $j=0,1$, with $h_{\rm min}=\displaystyle \min_{0\leq i\leq n} x_{i+1}-x_i$.