# Parameter Extraction of Photovoltaic Cells and Panels Using a PID-Based Metaheuristic Algorithm
## 2 Materials and Methods
### The Proposed Algorithm
#### 2.3.2 Calculating System Deviations  
The algorithm performs the current and previous errors of the deviation signal only within the main iterative loop. To improve performance, an initial calculation of the deviation signal is also conducted outside the main loop, providing starting values for the incremental PSA and setting the baseline for further calculations. The errors show how the current matrix of solutions from the previous iteration differs from the optimal solution. The primary iterative process begins, which runs for a maximum number of generations. In each generation, the algorithm calculates the fitness function of each solution. If a solution performs better than the previously identified best solution, it is replaced as the best new solution. Then, the algorithm updates the calculation of current and previous errors in each generation, following the PSA. The difference between the best and current solutions forms the basis for updating the errors. The current and previous errors of iteration \(t\) are defined as follows:  
\[\mathbf{e}_{k}(t)=\mathbf{x}^{\star}(t-1)-\mathbf{X}(t-1) \tag{8}\]  
\[\mathbf{e}_{k-1}(t)=\mathbf{e}_{k}(t-1)+\mathbf{x}^{\star}(t)-\mathbf{x}^{\star}(t-1) \tag{9}\]  
where \(\mathbf{x}^{\star}(t)\) is the best solution vector at iteration \(t\), and \(\mathbf{X}(t)\) is the matrix of all solutions at iteration \(t\). The deviation signal \(\mathbf{e}_{k}(t)\) is calculated as the difference between the historical best individual \(\mathbf{x}^{\star}(t-1)\) and the current individual \(\mathbf{x}(t-1)\) at each iteration as shown in Equation (7). This approach eliminates the need for external detecting devices or a specialized controlling system to obtain the deviation signal, as it is derived inherently within the algorithm by tracking the progress of each individual in relation to the best-known solution in the search space. This internal feedback loop allows the PSA to autonomously adjust the control output based on the system's deviation without additional hardware requirements. Output values, zero output values, and a variable \(\eta\) are calculated. The output values utilize the PSA, with the PID coefficients applied to a weighted sum of the current error, the difference between current and previous errors, and the difference between the current and twice the previous errors plus the two-step errors, as in the following:  
\[\Delta\mathbf{u}(t)=K_{p}*\mathbf{r}_{2}*[\mathbf{e}_{k}(t)-\mathbf{e}_{k-1}(t)]+K_{i}*\mathbf{r}_ {3}*\mathbf{e}_{k}(t)+K_{d}*\mathbf{r}_{4}*[\mathbf{e}_{k}(t)-2\mathbf{e}_{k-1}(t)+\mathbf{e}_{k-2 }(t)] \tag{10}\]  
where the PID coefficients \(K_{p}\), \(K_{i}\), and \(K_{d}\) are the proportion, integral, and differential adjustment coefficients, respectively; and \(\mathbf{r}_{2}\), \(\mathbf{r}_{3}\), and \(\mathbf{r}_{4}\) are vector matrices containing random numbers between 0 and 1. The zero output values utilize the Levy flight function \(\mathbf{L}\), providing an exploration mechanism to avoid local minima. The variable \(\eta\), used to balance the influence of the output and zero output values, decreases with progressing generations. The zero output values are defined as follows:  
\[\mathbf{o}(t)=[cos(1-t/T)+\lambda\mathbf{r}_{5}*\mathbf{L}]*\mathbf{e}_{k}(t) \tag{11}\]  
By replacing:  
\[\lambda=\left[\frac{ln(T-t+2)}{ln(T)}\right]^{2} \tag{12}\]  
\[\mathbf{L}=\frac{u\sigma}{\left|\mathbf{v}\right|^{1/\beta}};\sigma=\left[\frac{\Gamma (1+\beta)\times sin\left(\frac{\pi\beta}{2}\right)}{\Gamma\left(\frac{(1+\beta )}{2}\right)\times\beta\times 2^{\frac{\beta-1}{2}}}\right]^{\frac{1}{\beta}} \tag{13}\]  
With \(\mathbf{u}\) and \(\mathbf{v}\) being matrices of randomly generated numbers coming from a standard normal distribution, \(\beta\) a factor set to 2, and \(\mathbf{r}_{5}\) a vector of random numbers from 0 to 1.