# Altitude Optimization and Task Allocation of UAV-Assisted MEC Communication System
## 3 Altitude of UAV and Task Allocation Optimization  
In this section, the main results are presented to solve the problem of (14a). We derive a semi closed-form expression of the optimal altitude of the UAV and a closed-form expression of the optimal task allocation ratio, which are shown in the following results. Theorem 3.1: _According to optimization problem (14a), the optimal flying altitude of the UAV can be expressed as_  
\[H^{opt}=\frac{-At(H)}{2\eta_{\text{NLoS}}[1+at(H)]^{2}+2(\eta_{\text{LoS}}- \eta_{\text{NLoS}})[1+at(H)]}, \tag{15}\]  
_where_  
\[A=\frac{180}{\pi}(\eta_{\text{LoS}}-\eta_{\text{NLoS}})abr, \tag{16}\]  
\[t(H)=\exp\Big{[}-b\Big{(}\frac{180}{\pi}\arctan\Big{(}\frac{H}{r}\Big{)}-a \Big{)}\Big{]}, \tag{17}\]  
_the optimal task allocation ratio of the UAV is given by_  
\[\alpha^{opt}=\frac{\frac{1}{\text{R}_{\text{ES}}}+\frac{C}{\text{J}_{\text{ BS}}}}{\frac{1}{\text{R}_{\text{UAV}}}+\frac{C}{\text{J}_{\text{UAV}}}+\frac{1}{ \text{R}_{\text{BS}}}+\frac{C}{\text{J}_{\text{BS}}}}. \tag{18}\]  
Proof of Theorem 3.1.: Our aim is to minimize the total system delay, which depends on the maximum value of the transmission and computation delay of both S2A and S2G links, i.e., \(\min\max\left\{t_{\text{S2A}}+t_{\text{UAV}},t_{\text{S2G}}+t_{\text{BS}}\right\}\). On the one hand, in the case of low flying altitude \(H\), due to the stronger path loss of NLoS than LoS, the average path loss increases, which makes the transmission delay of the S2A link increase, resulting in an increase of the total system delay. On the other hand, when the flying altitude \(H\) is higher, the rate of user uplink transmission tasks to the UAV decreases, which makes the transmission delay of the S2A link increase, resulting in an increase of the total system delay. Therefore, there exists an optimal \(H\) that makes \(t_{\text{S2A}}+t_{\text{UAV}}=t_{\text{S2G}}+t_{\text{BS}}\). We denote \(t_{\text{S2A}}+t_{\text{UAV}}\) as \(T_{1}\), and denote \(t_{\text{S2G}}+t_{\text{BS}}\) as \(T_{2}\). Substituting (10) and (12) into \(T_{2}\), we obtain \(T_{2}=\frac{(1-a)L}{\text{R}_{\text{BS}}}+\frac{(1-a)LC}{\text{J}_{\text{BS}}}\), which is independent of \(H\). Substituting the rate of the user's uplink transmission task to UAV in (6) into (9), the transmission delay of the S2A link can be obtained, and the expression of \(T_{1}\) is expressed  
\[T_{1}=\frac{\alpha L}{B_{\text{UAV}}\log_{2}\Big{(}1+\frac{p_{G}}{Q\text{N}_{ \text{LoS}}\eta(H)}\Big{)}}+\frac{\alpha LC}{f_{\text{UAV}}}, \tag{19}\]  
where  
\[Q=\Big{(}\frac{4\pi f_{c}}{c}\Big{)}^{2}, \tag{20}\]  
\[s(H)=H^{2}+r^{2}, \tag{21}\]  
\[g(H)=s(H)\Big{[}\eta_{\text{NLoS}}+\frac{\eta_{\text{LoS}}-\eta_{\text{NLoS} }}{1+at(H)}\Big{]}. \tag{22}\]  
In order to find an optimal altitude \(H^{opt}\), then according to (19), which is equivalent to minimizing \(g(H)\), the first order derivative with respect to \(H\) is obtained as  
\[g^{\prime}(H)=2\eta_{\text{NLoS}}H+\frac{2(\eta_{\text{LoS}}-\eta_{\text{NLoS }})H}{1+at(H)}+\frac{At(H)}{[1+at(H)]^{2}}. \tag{23}\]  
Let \(g^{\prime}(H)\) equals zero, and since \(1+at(H)>0\) holds, we have  
\[2\eta_{\text{NLoS}}gH[1+at(H)]^{2}+2(\eta_{\text{LoS}}-\eta_{\text{NLoS}})H[1+ at(H)]+At(H)=0. \tag{24}\]The optimal flying altitude of the UAV in (15) can be obtained by arranging the above formula. Substituting (9) and (11) into \(T_{1}\), we get \(T_{1}=\alpha(\frac{L}{R_{\rm UAV}}+\frac{LC}{J_{\rm UAV}})\), and \(T_{1}\) is monotonically increasing with respect to \(\alpha\), while \(T_{2}=(1-\alpha)(\frac{L}{R_{\rm BS}}+\frac{LC}{J_{\rm BS}})\) is monotonically decreasing with respect to \(\alpha\). Then according to (13), \(T\) has the minimum value when satisfying \(T_{1}=T_{2}\), and \(T_{1}=T_{2}\) can be expressed as  
\[A=\frac{180}{\pi}(\eta_{\text{LoS}}-\eta_{\text{NLoS}})abr, \tag{16}\]0  
By arranging the above formula, we can get the optimal task allocation ratio in (18). From Theorem 1, we can see that the optimal flying altitude of the UAV depends on the distance between the UAV's projection and the user.