For high speed flows with a short duration of test time, one has to construct an optical system without having an image of it, which can be obtained only after running an experiment. In order to solve this problem, we propose a technique to simulate the shadowgraph method together with the flow field by computer in this paper, so that one can optimize the optical system on a computer before experiment. In the technique, the experiment is represented by the solution given by computational fluid dynamics (CFD), and the image is obtained by tracing rays through the numerical solution as well as the optical setup. The effects of optical components, such as the location of lens, the size of pinhole, the location of image plane, are analyzed. Having this technique, even a beginner can construct an optimized shadowgraph system at a negligible cost. The technique proposed can be used for analyzing schlieren system as well.