I am writing this algorithm and this what I have as a result. The \for and \while ... doesn't appear.

\caption{Calculate the exact surface of PV  $A_p{v}$ }
\REQUIRE $ Nmax_{wt}$\\
\FOR{$i=0:1:Nmax_{wt}$}: \\
\STATE $Npvmax = upperbound$\\
\STATE $Npvmin = 0$\\
\STATE $Pw(t) = P_w(t) \times i$ \\
    \WHILE{$Npvmax - Npvmin \geq 1$}\\
        \STATE $Npv = (NpvMax + NpvMin) / 2$\\
        \STATE $Ppv(t) = Ppv(t) \times i$ \\
        \STATE $Pre(t) = Ppv(t) + Pw(t)$\\
        \STATE proceed Sizing Storage\\
        \IF{$LOH(T) \leq LOH_0$ }\\
            \STATE $Npvmin \leftarrow Npv / x$\\
            \STATE $NpvMax \leftarrow Npv$\\
\STATE Return (Npv)

enter image description here

  • 2
    Welcome to TeX.SE! Please make your code fragment compilable, i.e. as complete small document, which we can copy and compile as it is. – Zarko Jun 6 at 10:03

There are a couple of issues here:

  1. You ignored several compilation errors. Never do that!
  2. The syntax for \FOR is \FOR{<condition>} <text>\ENDFOR
  3. Do not put \\ at the end of lines. algorithmic will automatically take care of breaking lines.
  4. You are using a lot of variables names with several letters in math mode, e.g. Nmax. All those names should be wrapped in \mathit{...}, otherwise the interword spacing/kerning of letters in those words will be bad.

Here's a compilable version of your algorithm:


\caption{Calculate the exact surface of PV  $A_p{v}$ }
\REQUIRE $ Nmax_{wt}$
\STATE{$Npvmax = upperbound$}
\STATE $Npvmin = 0$
\STATE $Pw(t) = P_w(t) \times i$
    \WHILE{$Npvmax - Npvmin \geq 1$}
        \STATE $Npv = (NpvMax + NpvMin) / 2$
        \STATE $Ppv(t) = Ppv(t) \times i$
        \STATE $Pre(t) = Ppv(t) + Pw(t)$
        \STATE proceed Sizing Storage
        \IF{$LOH(T) \leq LOH_0$ }
            \STATE $Npvmin \leftarrow Npv / x$
            \STATE $NpvMax \leftarrow Npv$
\STATE Return (Npv)

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy