## 2 Materials and Methods
### Application of the Control Strategies to the WWTP
#### 2.3.1 Control Problem Formulation  
At each sampling time, the controller receives information from the plant and translates this information to the variables considered by the control algorithm. The non-linear process model described by Equations (A1)-(A11) is used as a prediction model (Equation (1) in Section 2). Then, the controller optimization problem is solved, taking into account the reduced model variables and the computed manipulated variables that are sent to the plant. Therefore, the control problems presented in Section 2 are written here in terms of the reduced model variables. A schematic representation of the proposed control strategy in the BSM1 plant is presented in Figure 3.  
The formulation of the control problem in this work considers a multivariable strategy, where reference values of the nitrates concentration, \(S_{\text{NO2\_SP}}=1\) g/m\({}^{3}\); and dissolved oxygen concentration, \(S_{\text{O5\_SP}}=2\) g/m\({}^{3}\); are provided manually or by an upper level optimization for a long time-operating horizon. The manipulated variables are \(KLa\) and \(Q_{a}\). Regarding the control variables, the control performance is expressed in terms of the vector of output variables \(\mathbf{y}(t)=\left[ \begin{array}{cc}S_{\text{NO1}}&S_{\text{O2}}\\ \end{array} \right]\) and the set points \(\mathbf{y}_{\mathbf{SP}}=\left[ \begin{array}{cc}S_{\text{NO1}\_SP}&S_{\text{ NO2\_SP}}\\ \end{array} \right]\). Therefore, the MPC performance index \(J_{NMPC}(\mathbf{\hat{x}}(t),\mathbf{u}(t))\) includes only the predicted values of the controlled variables \(\mathbf{y}(t)\), which are selected from the state vector \(\mathbf{x}(t)\), and the manipulated inputs \(\mathbf{u}(t)=\left[ \begin{array}{cc}Q_{a}&KLa\\ \end{array} \right]\), considering that the control signal is constant along the prediction horizon. Moreover, the controller only receives measurements of the influent variables that are considered in the reduced model and have a significant effect in the plant performance, which are the influent flow, ammonium concentration, and organic matter concentration. Summarizing, the specific WWTP control problem variables considered in this application are:  
* State vector: \(\mathbf{x}(t)=\left[ \begin{array}{cc}S_{\text{NH1}}&S_{\text{NH2}}&S_{\text{ NO1}}&S_{\text{NO2}}&S_{\text{S1}}&S_{\text{S2}}&S_{\text{O1}}&S_{\text{O2}} \end{array} \right]\)
* Output variables (controlled variables): \(\mathbf{y}(t)=\left[ \begin{array}{cc}S_{\text{NO1}}&S_{\text{O2}}\end{array} \right]\)
* Measured disturbances: \(\mathbf{v}(t)=\left[ \begin{array}{cc}Q_{in}&S_{S,in}&S_{NH,in}\end{array} \right]\)
* Vector of manipulated inputs: \(\mathbf{u}(t)=\left[ \begin{array}{cc}Q_{a}&KLa\end{array} \right]\)
* Set points: \(S_{\text{NO1},SP}=1\) mg/L and \(S_{\text{O2},SP}=2\) mg/L  
The control performance index is the following equation, which includes a term for set-point tracking error, control movements and a terminal penalization for set-point tracking:  
\[J_{\text{NMPC}}(\hat{\mathbf{y}}(t),u(t))=|\hat{\mathbf{y}}(t)-\mathbf{y}_{SP }|_{\mathbf{Wy}}^{2}+|\mathbf{u}(t)-\mathbf{u}(\tau_{k-1})|_{\mathbf{Wu}}^{2} +|\hat{\mathbf{y}}(\tau_{N})-\mathbf{y}_{SP}|_{\mathbf{Wn}}^{2} \tag{7}\]  
where \(\mathbf{W_{y}}\) is the weight matrix for the corresponding controlled states, \(\mathbf{W_{u}}\) is a weight matrix for the control efforts, and \(\mathbf{W_{n}}\) is a weight matrix for the terminal penalization. The operator \(|\cdot|_{\mathbf{Q}}^{2}\) is used to denote the square of a weighted Euclidean norm of a vector, where \(Q\) is a positive definite matrix. The economic performance (\(J_{\text{ECO}}\)) is measured using the overall cost index (\(OCI\)) described by Equation (6), which includes the pumping energy, aeration energy and fines for off-specification ammonium concentration. \[J_{\text{ECO}}=w_{1}\cdot\frac{1}{t}\left(\int\limits_{t_{0}}^{tf}(0.004\cdot Q _{a}(t))dt \begin{array}{cc}+\frac{S_{\text{Oeff}}}{1800}\int\limits_{t_{0}}^ {tf}V_{2}\cdot KLa(t)dt\end{array}