In my thesis, I will first introduce CASTEP, a first principle calculation program. Then I will describe how I learned the relation between the equation of second harmonic generation (SHG) and the tool SHG code, and how to use it to obtain the SHG coefficients form a CASTEP optics calculation result. Finally, I use this experience to implement the equation of the third harmonic generation (THG) into a computer code. I will introduce the approximate or conversion formulas that I use in my code, and compare my results with them from other research groups.