The equations to be solved in order to determine the best discrete-valued approximation to a given electron or scattering-length density function are worked out. A simple illustration is reported.