We introduce a numerical method to obtain approximate eigenvalues for some problems of Sturm-Liouville type. As an application, we consider an infinite square well in one dimension in which the mass is a function of the position. Two situations are studied, one in which the mass is a differentiable function of the position depending on a parameter $b$. In the second one the mass is constant except for a discontinuity at some point. When the parameter $b$ goes to infinity, the function of the mass converges to the situation described in the second case. One shows that the energy levels vary very slowly with $b$ and that in the limit as $b$ goes to infinity, we recover the energy levels for the second situation.