# The Cascade Control of Natural Gas Pipeline Systems
## 2 Cascade Control Algorithm
### Linear Quadratic Regulator  
The natural gas pipelines are self-balanced systems. It is easy to get a PID cascade control by tuning the parameters of the inner and outer loop PID controllers. To get the desired steady state quickly and cost effectively, the linear quadratic regulator (LQR) is used for the controller design.  
\[J=\frac{1}{2}\int_{0}^{\infty}(x^{T}Qx+u^{T}Ru)dt, \tag{8}\]  
where \(J\) is the optimization of performance index. \(Q\) is a positive semi define symmetric weight matrix, and \(R\) is a positive define symmetric weight matrix. In the LQR control, different \(Q\) and \(R\) are selected for different performance requirements. \(Q\) is related with the regulation speed and \(R\) is related with the control ability. The optimization of \(J\) is to minimize the transient time and energy consumption. An experienced dispatcher of the natural gas pipeline can adjust the pipeline to a new steady state in very short time. Thus, both the transfer time and the cost are meaningful to the cascade control when the accuracy of the end state is guaranteed by the LQR controller. In actual pipeline system, all states of the dynamic equation of the pipeline section is hard to obtain. Thus, the controller design is based on the measured pressure and flow rate. The output feedback LQR is solved in time domain. The value of initial state \(x(0)\) will affect the calculation of the optimal performance. To avoid this problem, the optimization of performance index \(J\) is turned into searching the minimum value of expected value \(E(J)\).  
\[E(J)=\frac{1}{2}E\{\int_{0}^{\infty}(x^{T}Qx+u^{T}Ru)dt\}=\frac{1}{2}E\{x^{T}( 0)Px(0)\}=\frac{1}{2}tr(PX) \tag{9}\]\[0=A_{c}^{T}P+A_{c}P+C^{T}\mathbf{K}^{T}R\mathbf{K}C+Q \tag{10}\]  
\[0=A_{c}S+SA_{c}^{T}+X \tag{11}\]  
\[\mathbf{K}=R^{-1}B^{T}PSC^{T}(CSC^{T})^{-1}, \tag{12}\]  
where \(X=E\{x(0)x^{T}(0)\}\) is an \(n\times n\) autocorrelation matrix of initial state and it is assumed as identity matrix \(I\) in the calculation. \(A_{c}=A-B\mathbf{K}C\) is asymptotically stable, \(S\) is the Lagrange multiplier, and \(P\) and \(S\) are solutions of the Lyapunov equation. An iterative calculation of feedback gain matrix \(\mathbf{K}\) is as follows.  
* (1) Initialization: Let \(k=0\), the initial \(\mathbf{K}_{0}\) is solved by \(A-B\mathbf{K}_{0}C\) asymptotically stable.
* (2) The \(k\) th iteration: Let \(A_{k}=A-B\mathbf{K}_{k}C\), \(P_{k}\), \(S_{k}\) are solved following Lyapunov equation.
* (3) Solving iterative direction of gain matrix \(\Delta\mathbf{K}\): Let \(J_{k}=\frac{1}{2}tr(P_{k}X)\), \(\Delta\ \mathbf{K}=R^{-1}B^{T}P_{k}S_{k}C^{T}(CS_{k}C^{T})^{-1}-\mathbf{K}_{k}\).
* (4) Solving iteration matrix: Let \(\mathbf{K}_{k+1}=\mathbf{K}_{k}+\alpha\Delta\mathbf{K}\) and \(\alpha\ \in(0,1]\) satisfies the following conditions, \(A-B\mathbf{K}_{k+1}C\) is asymptotically stable, and \(J_{k+1}=\frac{1}{2}tr(P_{k+1}X)\leq J_{k}\).
* (5) Determine whether iteration is needed: If the difference between \(J_{k+1}\) and \(J_{k}\) is small enough, then go to (6); otherwise, let \(k=k+1\) and go to (2).
* (6) Termination: Let \(\mathbf{K}=\mathbf{K}_{k+1}\), \(J=J_{k+1}\).  
Here, the output feedback gain matrix can be found by the iterative algorithm if it satisfies the following four conditions.  
* There is a matrix \(\mathbf{K}\) to make \(A_{c}=A-B\mathbf{K}C\) asymptotically stable. Since the pipeline system is a self-balance system, the initial matrix can be calculated by using the eigenvalue assignment method.
* The system output matrix \(C\) is full row rank.
* To get all control inputs in the performance index, the weighted matrix \(R\) must be positive definite.
* The state weight matrix \(Q\) is semi positive definite. \((\sqrt{Q},A)\) is detectable, which means that the unstable state in the index is weighted.