I'm not sure that I understand what you are doing, but I think that you could use the fminbnd solver along with some interpolation or floor or ceiling function.
First, compute all of the tail sums. I assume that your psi vector is a row vector.
tails = cumsum(fliplr(psi));
If I am right, tails(1) is now the sum of all of the elements in psi, and tails(end) is psi(nmax).
Now to look for the element of tails that best matches your criterion, do fminbnd on the function
fun = @(x)tails(floor(x));
Well, you put in your criterion, but you see that fun takes a continuous argument and immediately takes the floor of that argument so it is only working on integers.
I think that you can take it from here. Good luck,
MATLAB mathematical toolbox documentation