This paper discusses the stabilising problems of a nonlinear and multivariate underactuated systems, also known as Inverted Pendulum (IP) systems. The attitude control of a nonlinear IP system is thus considered. One of the most important techniques, a Linear Quadratic Regulator (LQR), is used in this paper to design a controller for an IP system. The structure of LQR parameters is based on weight matrices, and the adjustment of the weight matrices parameters is the most challenging part of this, being normally computed by repeating trials and adjusting based on successful or unsuccessful outcomes. The difficulty in guessing the optimum matrices and achieving automatic adjustment of the weighting matrices is mitigated by the introduction of a metaheuristic algorithm to investigate the optimal solution; this is based on a swarm of particles moving in a virtual space. The proposed approach successfully stabilised the IP system in the upright position and removed perturbations; the simulated results thus showed satisfactory performance of the suggested control method.