In order to illustrate the significance of the fact that even the boundary conditions for a differential equation are to be accurately approximated when difference methods are used, we examine the differential equation
y^{\prime \prime}=y,
with boundary conditions y^{\prime}(0)=0, y(1)=1, which has the solution y(x)=\frac{\cosh x}{\cosh (1)}.
We put x_{n}=n h, assume that 1 / h is an integer and use the difference approximation
y_{n}^{\prime \prime} \approx\left(y_{n+1}-2 y_{n}+y_{n-1}\right) / h^{2} .
Two different representations for the boundary conditions are
(1) symmetric case : y_{-1}=y_{1} ; y_{N}=1, N=1 / h,
(2) non-symmetric case
y_{0}=y_{1}, y_{N}=1.
(a) Show that the error y(0)-y_{0} asymptotically approaches a h^{2} in the first case, and b h in the second case, where a and b are constants to be determined.
(b) Show that the truncation error in the first case is O\left(h^{2}\right) in the closed interval [0,1].
(a) Substituting the second order difference approximation into the differential equation, we get the difference equation
y_{n+1}-2\left(1+\frac{h^{2}}{2}\right) y_{n}+y_{n-1}=0.
The characteristic equation is given by
\xi^2-2\left(1+\begin{array}{c} h^2 \\ 2 \end{array}\right) \xi+1=0
The solution of the difference equation may be written as
y_{n}=C_{1} e^{n h}\left(1-\frac{n}{24} h^{3}+O\left(h^{4}\right)\right)+C_{2} e^{-n h}\left(1+\frac{n}{24} h^{3}+O\left(h^{4}\right)\right)
where C_{1} and C_{2} are arbitrary parameters to be determined with the help of the discretization of the boundary conditions.
(1) Symmetric case : We have y_{-1}=y_{1}. Hence, we obtain
\begin{aligned} & C_{1} e^{h}\left(1-\frac{1}{24} h^{3}+O\left(h^{4}\right)\right)+C_{2} e^{-h}\left(1+\frac{1}{24} h^{3}+O\left(h^{4}\right)\right) \\ = & C_{1} e^{-h}\left(1+\frac{1}{24} h^{3}+O\left(h^{4}\right)\right)+C_{2} e^{h}\left(1-\frac{1}{24} h^{3}+O\left(h^{4}\right)\right) \end{aligned}
We get C_{1}=C_{2}.
Next, we satisfy y_{N}=1, N h=1.
y_{N}=C_{1} e\left(1-\frac{1}{24} h^{2}+O\left(h^{3}\right)\right)+C_{2} e^{-1}\left(1+\frac{1}{24} h^{2}+O\left(h^{3}\right)\right)=1 .
Since C_{1}=C_{2}, we obtain
\begin{aligned} C_{1} & =\frac{1}{\left[2 \cosh (1)-\left(h^{2} / 12\right) \sinh (1)+O\left(h^{3}\right)\right]} \\ & =\frac{1}{2 \cosh (1)}\left[1-\frac{h^{2} \sinh (1)}{24 \cosh (1)}+O\left(h^{3}\right)\right]^{-1} \\ & =\frac{1}{2 \cosh (1)}\left[1+\frac{h^{2} \sinh (1)}{24 \cosh (1)}+O\left(h^{3}\right)\right] \end{aligned}
The solution of the difference equation becomes
\begin{aligned} & y_{n}=C_{1}\left[2 \cosh x_{n}-\frac{x_{n} h^{2}}{12} \sinh x_{n}\right] . \\ & y_{0}=2 C_{1}=\frac{1}{\cosh (1)}+\frac{h^{2}}{24} \frac{\sinh (1)}{\cosh ^{2}(1)}+O\left(h^{3}\right) . \end{aligned}
We get from the analytic solution y(0)=1 / \cosh (1).
Hence, we have y(0)-y_{0}=a h^{2},
where a=-\frac{1}{24} \frac{\sinh (1)}{\cosh ^{2}(1)}=-0.020565 .
(2) Non-symmetric case: y_{0}=y_{1}, y_{N}=1.
Satifying the boundary conditions, we obtain
C_{1}+C_{2}=C_{1} e^{h}+C_{2} e^{-h}+O\left(h^{3}\right),
or \left(e^{h}-1\right) C_{1}=\left(1-e^{-h}\right)=C_{2}+O\left(h^{3}\right),
or \left[h+\frac{h^2}{2}+O\left(h^3\right)\right] C_1=\left[h-\frac{h^2}{2}+O\left(h^3\right)\right] C_2
or C_1=\left\{\left(1+\frac{h}{2}\right)^{-1}\left(1-\frac{h}{2}\right)+O\left(h^2\right)\right\} C_2=\left[1-h+O\left(h^2\right)\right] C_2 \text {. }
y_N=C_1 e+C_2 e^{-1}+O\left(h^3\right) \text {, }
or 1=\left[(1-h) e+e^{-1}+O\left(h^2\right)\right] C_2 \text {. }
Neglecting the error term, we obtain
\begin{aligned} C_{2} & =\frac{1}{2 \cosh (1)-h e}=\frac{1}{2 \cosh (1)}\left[1-\frac{h e}{2 \cosh (1)}\right]^{-1} \\ & =\frac{1}{2 \cosh (1)}\left[1+\frac{h e}{2 \cosh (1)}\right], \end{aligned}
where the O\left(h^{2}\right) term is neglected.
C_{1}=(1-h) C_{2}=\frac{1}{2 \cosh (1)}\left[1-h+\frac{h e}{2 \cosh (1)}\right]
where the O\left(h^{2}\right) term is neglected.
We have b h=12 a h, \quad \text { or } \quad b=12 a=-0.24678 .
(b) Hence, from (a), in the symmetric case the truncation error is O\left(h^{2}\right) while in the nonsymmetric case it is O(h).