代码模板
\begin{algorithm}[!h]
\caption{Optimization of Communication Power of the Relay for Given Trajectory}
\begin{algorithmic}[1]
\STATE Initialize the number of time slots $K$, the minimum data rate $R_0$ and the maximum energy consumption $E_A$ and $E_M$. Initialize the relay trajectory ${x_k,y_k}$ for each time slot $k$ and the circuit power consumption $p_c$;
\STATE Initialize the maximum iterative number $J$ and the Lagrange dual variables $\bm{\lambda}$, $\zeta$ and $\xi$;
\STATE Obtain $\widetilde{R}_{MB,k}$ by solving $\beta\left( R_{MB,k}\right)=0$ with the method of bisection;
\IF {$\widetilde{R}_{MB,k}\leq R_0$}
\STATE $R_{MB,k}=R_0$;
\ELSE
\STATE Record the time slot number $k$ for $\widetilde{R}_{MB,k}$ in $\bm{b}$;
\ENDIF
\REPEAT
\STATE Find $\left\lbrace R_{AM,k},R_{MB,b}\right\rbrace=\arg\max L \left(\left\lbrace R_{AM,k},R_{MB,b}\right\rbrace,\left\lbrace\lambda_k, \zeta,\xi\right\rbrace\right)$;
\STATE Update $\lambda_k$, $\zeta$ and $\xi$ with ($14$), ($15$), ($16$) subject to $\lambda_k\geq 0$, $\zeta\geq 0$ and $\xi\geq 0$;
\UNTIL {The dual variables reach a convergence or $j=J$}
\STATE Output $p_{A,k}$ and $p_{B,k}$;
\end{algorithmic}
\end{algorithm}
范例
摘自 Duan R, Wang J, Jiang C, et al. Resource allocation for multi-UAV aided IoT NOMA uplink transmission systems[J]. IEEE Internet of Things Journal, 2019, 6(4): 7025-7037.