A series solution for certain Ricatti equations with applications to Sturm-Liouville problems