Exact finite difference solution for constant second derivative (source code)

= Exact finite difference solution for constant second derivative
{title2=$y_{n-1}-2y_n+y_{n+1}=c h^2$}

On a uniform mesh $x_n=a+nh$, the centered second <finite difference> is exact for every quadratic <polynomial>. In particular, for $y''=c$ with endpoint <boundary conditions>, the unique discrete solution equals the exact quadratic solution at every mesh point. Subtracting consecutive first differences reduces the equation to $d_{n+1}-d_n=ch^2$, so $y_n=\tfrac12ch^2n(n-1)+d_1n+y_0$. The second endpoint determines $d_1$. Uniqueness follows because any difference of two discrete solutions has zero second <finite difference>, hence is linear in the mesh index and vanishes at both endpoints. Exact nodal values in this example do not imply that a general <finite difference method> is exact for other <ordinary differential equations>.