A nonlinear equation and its application to nearest neighbor spacings for zeros of the zeta function and eigenvalues of random matrices