Compared to rotary machines, tubular permanent magnet linear synchronous machine (TPMLSM) has many advantages, such as simple construction and excellent dynamic performance. In the current paper, an enhanced particle swarm optimization (PSO) algorithm is utilized to minimize the detent force of TPMLSM. The proposed optimization method can automatically determine the number of particles to reduce the number of particles and promote computational efficiency. Specifically, maintaining the number of particles in the exploration phase and alleviating the number of particles in the exploitation stage, and the stage in exploitation or exploration, are determined by the difference between the gbest’s present and past cost values. The algorithm’s efficiency is evaluated on the six-hump camel back, Goldstein-Price, and 3-D Hartman functions. Then, the TPMLSM is optimized using the improved PSO algorithm, aiming at minimizing the detent force. The calculation results indicate that the value of detent force is reduced 56.3 and 64.8% for positive maximum and negative maximum value, respectively. Finally, a prototype was manufactured according to the optimized dimensions and structure, and an experimental platform was constructed to verify the TPMLSM’s electromagnetic performance. The experimental test verifies the feasibility and design validity of the optimization algorithm.