The main purpose of this paper is determination of suitable weighting matrices to design a linear quadratic optimal controller for an inverted pendulum using the artificial bee colony algorithm. It is challenging to select appropriate weighting matrices for a linear quadratic optimal control system and there is no relevant systematic techniques presented for this goal. Generally, selecting these weights is performed by trial and error method which is based on designer's experience and time consuming. Also there is no direct relation between weighting matrices' values and time domain specifications like settling time, overshoot and steady state error. In this paper, the artificial bee colony algorithm has been used for selecting weighting matrices to overcome these difficulties. The artificial bee colony algorithm is a swarm intelligence based optimization algorithm and inspired by honey bees' swarming around their hive. It can be efficiently used for multivariable, multimodal function optimization. Simulation results show that the artificial bee colony algorithm is very efficient and robust in comparison with trial and error method.