## 3 Results and Discussion
### Optimization Logic  
In order to approximate the dynamics of the inverted pendulum, the universe of discourse for each of the four states of the system (positions \(\theta\), \(x\) and velocities \(\dot{\theta}\), \(\dot{x}\)) was partitioned in \(p_{ij}=5\) (\(j=1,2\)) fuzzy sets (membership functions), which were labeled as follows: \(A^{1}_{ij}=\text{NB}\) (Negative Big), \(A^{2}_{ij}=\text{NS}\) (Negative Small), \(A^{3}_{ij}=\text{Z}\) (Zero), \(A^{4}_{ij}=\text{PS}\) (Positive Small), \(A^{5}_{ij}=\text{PB}\) (Positive Big), and which were characterized by Gaussian functions. Then, to adjust the parameters of the input membership functions, we consider that the fuzzy sets are symmetric in the positive side and in the negative side with respect to the zero of the linguistic variable. This is exemplified in Figure 6 for the membership functions of variable \(\theta\). Thereby for each input there are five adjusting parameters (since they are symmetric): the centers of positive small and positive big functions and standard deviations of zero, positive small and positive big functions; therefore, a total of 20 parameters will be optimized for the four inputs. Due to the computational cost of the stated problem, we have opted to carry out the optimization in two stages; in the first one the optimized parameters are those of the membership functions for inputs \(\theta\) and \(x\), and in the second stage we optimize the parameters of the membership functions for inputs \(\dot{\theta}\) and \(\dot{x}\). By adjusting a total of 10 parameters per stage instead of 20 at once, we avoid the use of a much greater amount of iterations in every algorithm, unlike the low amount of iterations needed under the proposed approach, such as it is shown later. Figure 6: Outline of \(\theta\) input membership functions. The objective function used to optimize the adaptive fuzzy controller (22) is given by  
\[y=\sum_{i=\left(\frac{T}{t_{0}}\right)}^{\left(\frac{T}{t_{s}}\right)}\left[ \varrho_{1}\tilde{\theta}(i)^{2}+\varrho_{2}\tilde{x}(i)^{2}+\varrho_{3}\{\tau(i )-\tau(i-1)\}\right] \tag{45}\]  
where \(t_{0}\) is the initial time of interest, \(T\) is the final time of interest, \(t_{s}\) is the sample time and \(\varrho_{k}\left(k=1,2,3\right)\) are scaling factors which are meant to take all terms of the objective function to a similar order. Objective function (45) was designed such that the regulation error of the pendulum and the tracking error of the cart were reduced (attributable to the two first terms in the summatory) while still getting smooth control signals, for example, low noise in the control input (attributable to the third term in the summatory). In the first stage of optimization we used \(\varrho_{1}=1\) [rad\({}^{-2}\)], \(\varrho_{2}=1\) [m\({}^{-2}\)], \(\varrho_{3}=1\times 10^{-2}\) [N\({}^{-1}\)], meanwhile in the second stage we used \(\varrho_{1}=2\) [rad\({}^{-2}\)], \(\varrho_{2}=1\) [m\({}^{-2}\)], \(\varrho_{3}=1\times 10^{-2}\)[N\({}^{-1}\)]. These parameters were obtained heuristically. The parameters employed for each algorithm in both optimization stages are listed below  
**For PSO**  
* Stage 1: Particles=10, Iterations=15, \(\theta_{M}=0.5\), \(\alpha_{P}=2\) and \(\beta_{P}=2\). * Stage 2: Particles=10, Iterations=15 \(\theta_{M}=0.4\), \(\alpha_{P}=1\) and \(\beta_{P}=1\).