 The proposed method provides a significant improvement in the placement of capacitors in power systems with harmonic distortion. It uses sequential quadratic programming to optimize the placement of both fixed and switched capacitors while considering voltage magnitude, total harmonic distortion, individual harmonic distortion, and overstress constraints. Additionally, it incorporates a linear constraint on the global harmonic distortion index, which enables the determination of solutions that meet the specified harmonic distortion requirements. This makes the method more effective than existing methods such as genetic algorithms. This article was authored by Ignacio Perez Abril.