The residual-stress-gradient distribution just below the surface of a material is an important factor to consider during the engineering and design of a component. With the availability of an intense energy-tunable synchrotron x-ray source, it becomes easier to analyze the stress gradient below the surface, using a multi-energy x-ray diffraction method. A program was developed to efficiently determine possible experimental parameters using a sample with a known stress gradient distribution. In addition, this program can also calculate the stress gradient distribution below the surface taking into account experimental results. It also includes a subroutine for calculating the x-ray absorption coefficients of all of the elements, generalizing it for use with any material. As an example, in the present study, the relationship between x-ray energy and the residual stress gradient is discussed according to the calculated result for a silicon nitride composition.