## 2 Methodology
### Proposed Controller Design
#### 2.4.1 Controller Design  
Let us define the generalized error vector as  
\[\mathbf{e}=\left[ \begin{array}{cc}\tilde{y}&\hat{y}\end{array} \right]^{T}, \tag{20}\]  
where \(\tilde{y}=y_{d}-y\) is the generalized error, with \(y_{d}\) being the desired output which is given by (2), i.e., \(y_{d}=L\theta_{d}+x_{d}\), where \(\theta_{d}\) and \(x_{d}\) are the desired position of the pendulum and the desired trajectory of the cart respectively. By combining Equations (3) and (20) we get  
\[\dot{\mathbf{e}}=\frac{d}{dt}\left[ \begin{array}{c}\tilde{y}\\ \dot{\tilde{y}}\end{array} \right]=\left[ \begin{array}{c}\dot{\tilde{y}}\\ -F(\mathbf{x})-G(\mathbf{x})u+\tilde{y}_{d}\end{array} \right] \tag{21}\]  
Figure 4: Flowchart of the firefly algorithm (FFA) process. which can be considered as the error dynamics. Now to fulfill the control objective we designed a controller \(u\) such that the plant (21) follows accurately the desired output \(y_{d}\), or in other words to keep the error \(\ddot{y}\) bounded. The proposed control law is given by  
\[u=\frac{1}{\hat{G}}[-\hat{F}+\mathbf{k}^{T}\mathbf{e}+\ddot{y}_{d}]+\mathbf{k_{d}}^{T}\mathbf{ \ddot{x}} \tag{22}\]  
where \(\hat{F}=L\hat{f}_{1}(\theta,\dot{\theta}\mid\mathbf{\theta_{f_{1}}})+\hat{f}_{2}(x, \dot{x}\mid\mathbf{\theta_{f_{2}}})\) and \(\hat{G}=L\hat{g}_{1}(\theta,\dot{\theta}\mid\mathbf{\theta_{g_{1}}})+\hat{g}_{2}(x,\dot{x}\mid\mathbf{\theta_{g_{2}}})\) are the adaptive fuzzy actions which estimate \(F(\mathbf{x})\) and \(G(\mathbf{x})\) respectively, and  
\[\mathbf{k}=\left[ \begin{array}{cc}k_{1}&k_{2}\end{array} \right]^{T};\ \ \mathbf{k}_{d}=\left[ \begin{array}{cc}k_{d_{1}}&k_{d_{2}}&k_{d_{3}}&k_{d_{4}} \end{array} \right]^{T}\] \[\mathbf{\ddot{x}}=\left[ \begin{array}{cc}\theta&\dot{\theta}&x_{d}-x &\dot{x}_{d}-\dot{x}\end{array} \right]^{T}\]  
where \(k_{1}\), \(k_{2}\) are positive constants and \(k_{d_{i}}\) for \(i=1,\cdots,4\), are suitable feedback control gains. The adaptive fuzzy systems \(\hat{f}_{1}(\theta,\dot{\theta}\mid\mathbf{\theta_{f_{1}}}),\hat{f}_{2}(x,\dot{x} \mid\mathbf{\theta_{f_{2}}}),\hat{g}_{1}(\theta,\dot{\theta}\mid\mathbf{\theta_{g_{1}}})\), and \(\hat{g}_{2}(x,\dot{x}\mid\mathbf{\theta_{g_{2}}})\) are constructed as those described by (6) and (7) and may be expressed as in (8) and (9), i.e.,  
\[\hat{f}_{1}(\theta,\dot{\theta}\mid\mathbf{\theta_{f_{1}}}) =\mathbf{\xi_{1}}^{T}\mathbf{\theta_{f_{1}}},\ \ \hat{f}_{2}(x,\dot{x}\mid\mathbf{\theta_{f_{2}}})=\mathbf{\xi_{2}}^{T}\mathbf{\theta_{f_{2}}}\] \[\hat{g}_{1}(\theta,\dot{\theta}\mid\mathbf{\theta_{g_{1}}}) =\mathbf{\eta_{1}}^{T}\mathbf{\theta_{g_{1}}},\ \ \hat{g}_{2}(x,\dot{x}\mid\mathbf{\theta_{g_{2}}})=\mathbf{\eta_{2}}^{T}\mathbf{\theta_{g_{2}}}\]  
On the other hand, the adaptive laws used to update the free parameters were designed as  
\[\dot{\mathbf{\theta}}_{f_{1}} =-\gamma_{1}Le^{T}\mathbf{Pb}\mathbf{\xi_{1}}(\mathbf{\theta},\dot{\mathbf{\theta }}) \tag{23}\] \[\dot{\mathbf{\theta}}_{f_{2}} =-\gamma_{2}e^{T}\mathbf{Pb}\mathbf{\xi_{2}}(\mathbf{x},\dot{\mathbf{x}})\] (24) \[\dot{\mathbf{\theta}}_{g_{1}} =-\gamma_{3}Le^{T}\mathbf{Pb}\mathbf{\eta_{1}}(\mathbf{\theta},\dot{\mathbf{\theta }})u\] (25) \[\dot{\mathbf{\theta}}_{g_{2}} =-\gamma_{4}e^{T}\mathbf{Pb}\mathbf{\eta_{2}}(\mathbf{x},\dot{\mathbf{x}})u \tag{26}\]  
where \(\mathbf{P}\) and \(\mathbf{b}\) are defined further on in (33) and (28) respectively. The block diagram of the proposed controller is shown in Figure 5. The closed-loop equation is gotten by substituting control law (22) into system (21) and under some manipulations it can be expressed as  
\[\dot{\mathbf{e}}=\left[ \begin{array}{c}\dot{\dot{y}}\\ (\hat{F}-F)+(\hat{G}-G)u-\mathbf{k}^{T}\mathbf{e}-\hat{G}\mathbf{k_{d}}^{T}\mathbf{\ddot{x}} \end{array} \right]\]  
or also, it may be written into the vector form  
\[\dot{\mathbf{e}}=\mathbf{A}\mathbf{e}+\mathbf{b}\left[(\hat{F}-F)+(\hat{G}-G)u-\hat{G}\mathbf{k_{d} }^{T}\mathbf{\ddot{x}}\right] \tag{27}\]  
where  
\[\mathbf{A}=\left[ \begin{array}{cc}0&1\\ -k_{1}&-k_{2}\end{array}