This article uses Modelica language to create a plasma magnetic confinement system with a single charged particle. The physics used in the article is basically the equations of a charged particle moving in a magnetic field. The Modelica language is an object-oriented component-based programming language that can easily modularize the system. The geometric part represented by the program can be processed automatically after the input of parameters. At last, the program simulates three different operating conditions for a magnetic confinement system. The initial velocities and initial positions that are different from the standard case, and the combination of the two are selected as the experimental objects. By comparing with the simulation with the case without magnetic confinement, the results show that the confinement system is effective.