In this paper, targeted energy transfer from a nonlinear continuous system to a nonlinear energy sink (NES) is investigated. For this purpose, the equation of a nonlinear beam with simply supported ends, on which the NES is attached, is derived using RayleighRitz method and the Lagrange equation. Then, parameters of the NES are optimized by both sensitivity analysis and particle swarm optimization (PSO) method. Analysis of the energy transfer between the nonlinear beam and the NES is presented, using the complexification-averaging method, too. Attaching an NES to a nonlinear continuous system and using the PSO method to obtain the optimized parameters of the NES is a new development, presented in this work. Also, here, more than one mode of the beam has been considered for analysis of energy transfer between the NES and different modes of the primary system.