If we use 4 equally spaced intervals, then
\begin{equation*}
m=4\quad\text{and}\quad L=1 \quad \Rightarrow \quad h = \frac{L}{m}= \frac{1}{4}
\end{equation*}
and
\begin{equation*}
x_{0} = 0,\, x_{1} = .25,\, x_{2} = .5,\, x_{3} = .75,\, x_{4} = 1,\, \text{ and }x_{5} = 1.25\text{.}
\end{equation*}
The point \(x_{5} = 1.25\) is outside the region and thus fictional. The boundary condition at \(x_{0} = 0\) is implemented as
\begin{equation*}
u_{0} = 5\text{.}
\end{equation*}
For the insulated condition, we will require
\begin{equation*}
u_{5} = u_{3}\text{.}
\end{equation*}
This makes the central difference for \(u'(x_{4})\) be zero. We can write the differential equation as a difference equation
\begin{equation*}
\frac{u_{i-1}-2 u_{i} + u_{i+1}}{h^{2}}= -1
\end{equation*}
or
\begin{equation*}
u_{i-1}-2 u_{i} + u_{i+1}= -0.0625, \quad i = 1,2,3,4\text{.}
\end{equation*}
For \(i = 1\text{,}\) recalling that \(u_{0} = 5\text{,}\) we have
\begin{equation*}
5 - 2 u_{1} + u_{2} = -.0625 \quad \textrm{ or }\quad - 2 u_{1} + u_{2} = -5.0625\text{.}
\end{equation*}
For \(i=2\) and \(i=3\) we have
\begin{equation*}
u_{1} - 2 u_{2} + u_{3} = -.0625 \quad \textrm{ and }\quad u_{2} -2 u_{3} + u_{4} = -.0625\text{.}
\end{equation*}
For \(i=4\) we have
\begin{equation*}
u_{3} - 2 u_{4} + u_{5} = -.0625\text{.}
\end{equation*}
Note that we now have 5 unknowns in our problem: \(u_{1}, \ldots, u_{5}\text{.}\) However, from the boundary condition \(u_{5} = u_{3}\) and so we can eliminate \(u_{5}\) from our \(i=4\) equation and write
\begin{equation*}
2 u_{3} - 2 u_{4} = -.0625\text{.}
\end{equation*}
Summarizing, we can put the unknown quantities in a vector \(\ub = (u_{1},u_{2},u_{3},u_{4})'\) and write the equations as a matrix equation \(A \ub = \bb\) where
\begin{equation*}
A = \left( \begin{array}{cccc}-2 & 1 & 0 & 0 \\ 1 & -2 & 1 & 0 \\ 0 & 1 & -2 & 1 \\ 0 & 0 & 2 & -2\end{array} \right)
\end{equation*}
and
\(\bb = (-5.0625, -.0625, -.0625, -.0625)'\text{.}\) Solve this system and plot the results:
>> u = A \ b
>> u = [5 ; u]
>> x = 0:.25:1
>> plot(x,u,'d')
Then interpolate with a spline.