Calculation of the dielectric function for a semi-infinite crystal