\documentclass{article}
\usepackage{algorithm2e,algorithmicx,mathtools}
\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}
\begin{document}
\begin{algorithm}
\begin{algorithmic}
\State 1. Find all possible Euclidean distances between received symbols.\\
$d_{i} =\abs{r_i-r_j} , \mkern30mu$
$\begin{cases}
s.t. \mkern15mu j = i+1 ,\\
i \in\{1,…,(M-1)\}, \text{and} \\
j \in\{2,…,M\}
\end{cases}$\\
\Statex
\State 2. Sort all $d_{i}=[d_{1},...,d_{M-1}]$ in ascending order. Assuming initialized ascending order as,\\
$[d_{M-1}$ <, ... ,< $d_{1}]$.
\Statex
\caption{: Algorithm for best probability allocation order in 4-CSK-1PD}
\label{alg:1}
\end{algorithmic}
\For{$i$ \leq \mkern8mu $M$} {
\If{$r_i\in \{d_{1}\} \mkern10mu only$ }
{ $symbol \mkern15mu r_i \gets p_1$}
\ElseIf {$r_i\in \{d_{1},d_{2}\} \mkern10mu$ }
{$symbol\mkern15mu r_i\gets p_2$}
\ElseIf {$r_i\in \{d_{M-1},d_{M-2}\} \mkern10mu$ }
{ $symbol \mkern15mu r_i\gets p_3$}
\ElseIf {$r_i\in \{d_{M-1}\} \mkern10mu$ }
{ $symbol\mkern15mu r_i\gets p_4$}
}
\Return{(Symbols with assigned probabilities)}
\end{algorithm}
\end{document}
-
2You should provide a minimal working example.– José Carlos SantosNov 1, 2019 at 21:54
-
Welcome to TeX.SE.– MicoNov 1, 2019 at 23:14
1 Answer
In the line immediately below \end{algorithmic}
, there's a syntax error in
\For{$i$ \leq \mkern8mu $M$} {
The directives \leq
and \mkern
must occur in math mode.
Hence, change the line to either
\For{$i \leq \mkern8mu M$} {
or, better still,
\For{$i \leq M \mkern8mu$} {
Separately, you should also change
$[d_{M-1}$ <, ... ,< $d_{1}]$
to
$[d_{M-1} < \dots < d_{1}]$