In the teaching of optical courses, the aberration knowledge is abstract and students often feel it difficult to understand. According to this phenomenon, a new simulation algorithm, which is based on the analysis of chromatic and spherical aberration theory, is described in this paper; with Matlab as the programming language, the emulation programs of chromatic and spherical aberration are designed and the simulation figures are presented, from which the effect of parametric variation on aberration can be shown vividly and intuitively. And for students, this will be helpful in the mastery of aberration knowledge.