## 3 Mathematical Model for Swarm Control  
In this section, a mathematical model is formulated for a unit swarm (three UAVs). In order to make the model simple, it is assumed that all the UAVs are flying at the same altitude (2D flying pattern). The mathematical model for a 3D flying pattern is reserved for future work. In the presented unit swarm configuration, the leading UAV is regarded as the master and the two following UAVs are considered as slaves (see Figure 6). Accordingly, the moving parameters of slaves such as speed and direction are dependent on those of the master UAV. In order to avoid a collision, every element of a unit swarm must be at the safe distance. In a master-slave network configuration, there is need of a radar sensor on each element of the unit swarm. In fact, every master UAV of the unit swarm has the ability to communicate with two of its subsequent UAVs, as shown in Figure 7. Consequently, a sub-cluster is formed by joining multiple unit swarms. The expansion of the sub-cluster is the cluster swarm.  
Figure 4: Random forest model training on channel characteristics (RSS) of UAV at \(h=500\) m.  
Figure 5: Random forest model training on channel characteristics (power loss) of UAV at \(h=500\) m.  
A unit swarm is represented in the rectangular coordinate system in Figure 6. The UAVs' positions are \((x_{i}(t_{0}),y_{i}(t_{0}),z_{i}(t_{0}))\) while \(i\in\{0,1,2\}\). For simplicity, it has been assumed that the UAVs are at the same height (z = 0) and the inter UAV distance or guard distance is \((x(t_{0}),y(t_{0}))\). According to [26], the equation of the swarm movement can be written as below.  
\[\begin{split}\rho_{0,1}^{*}&=x_{0}(t_{0})-x_{1}(t_ {0})-x_{0,1}(t_{0})\\ \rho_{0,2}^{*}&=x_{0}(t_{0})-x_{2}(t_{0})-x_{0,2}(t_ {0})\\ \rho_{1,2}^{*}&=x_{1}(t_{0})-x_{2}(t_{0})-x_{1,2}(t_ {0})\end{split} \tag{4}\]  
where the necessary x-axes spacing for swarm elements are \(x_{0,1}(t_{0})\), \(x_{0,2}(t_{0})\) and \(x_{1,2}(t_{0})\), and the spacing error function is \(\rho^{*}(t_{0})\). The velocity of UAVs may be expressed as:  
\[\begin{split}\Delta^{\sigma}v_{1}&=\
abla v_{1}(t_ {0})-\overline{v}_{x}(t_{0})\\ \Delta^{\sigma}v_{2}&=\
abla v_{2}(t_{0})-\overline{ v}_{x}(t_{0})\end{split} \tag{5}\]  
The velocity equations (Equations (5)) belong to UAV\({}_{s1}\) and UAV\({}_{s2}\), whereas \(\
abla v(t_{0})\) and \(\overline{v}_{x}(t_{0})\) are the gradients of velocity and required velocities of UAVs. According to Figure 7 and Equation (5), the error function for velocities belonging to the \(n^{th}\) swarm element may be expressed as follows:  
Figure 6: Rectangular coordinate system-based representation of a unit swarm.  
Figure 7: Mater–slave hierarchy for UAV swarm flying formation.  
\[\Delta^{\sigma}v_{n}=\
abla v_{n}(t_{0})-\overline{v}_{xn}(t_{0}) \tag{6}\]  
Referring to [27], the acceleration of UAVs in any swarm configuration must be depend on the error function (\(\Delta^{\varepsilon}v_{n}\)) along the x-axes. In addition, the dynamic control rule along the \(x\) and \(y\) axis are defined as mentioned in reference [26].  
\[v_{a}^{x}(t_{0})=\alpha_{ax}\rho_{0,a}^{x}+\beta_{ax}[v_{0}(t_{0}-\tau_{0,a}(t_ {0}))-v_{a}(t_{0})]+\gamma_{ax}\rho_{a,b}^{x}+\zeta_{ax}[v_{0}(t_{0}-\tau_{a,b} (t_{0}))-v_{a}(t_{0})] \tag{7}\]  
On other hand, the velocity component is given as  
\[v_{a}^{y}(t_{0})=\alpha_{ay}\rho_{0,a}^{y}+\beta_{ay}[v_{0}(t_{0}-\tau_{0,a}(t_ {0}))-v_{a}(t_{0})]+\gamma_{ay}\rho_{a,b}^{y}+\zeta_{ay}[v_{0}(t_{0}-\tau_{a,b }(t_{0}))-v_{a}(t_{0})] \tag{8}\]  
In the above two expressions ((7) and (8)) \(a\
eq b\in=\{1,2\}\), the parameters \(\alpha_{ax}\), \(\beta_{ax}\), \(\gamma_{ax}\) and \(\zeta_{ax}\) are considered as the gains in the \(x\) component. Furthermore, \(\alpha_{ay}\), \(\beta_{ay}\), \(\gamma_{ay}\) and \(\zeta_{ay}\) are \(y\) components in two dimensional space. Moreover, the variable \(\tau_{a,b}\) is considered a time delaying function in the wireless communication.