Active magnetic bearings (AMBs) are relatively new members in bearings family. Against other bearings which support loads by forces produced by fluid film pressure or physical contact, AMBs support loads by magnetic fields without any contact with the shaft and make it to be levitated. Because of that feature, AMBs have lots of benefits in comparison with other bearings. This paper presents modelling of AMBs with one and two degrees of freedom and the necessary parameters and equations for control of them is driven. Then, a numerical method based on orthogonal functions called Direct Method for optimal control in AMBs is presented with or without inequality constraints. The approach consists of reducing the optimal control problem with a two-boundary-value differential equation to a set of algebraic equations by approximating the state and control variables. This approximation uses orthogonal functions with unknown coefficients. In addition, the inequality constraints are converted to equal constraints. The problems are solved using Legendre and Haar bases. Simulation results demonstrate the benefits of Legendre functions method in compared with those using Haar bases.