We study finite difference approximations of solutions of direct and inverse Sturm–Liouville problems, in a finite or infinite interval on the real line. The discretization is done on optimal grids, with a three-point finite difference stencil. The optimal location of the grid points is calculated via a rational approximation of the Neumann-to-Dirichletmap and the latter converges exponentially...