Optimal partitioning of an interval and applications to Sturm-Liouville eigenvalues