I am using packages \usepackage{algpseudocode}, \usepackage{algorithm} to run below algorithm but it gace error!

Undefined control sequence. l.1248 \IF $f(X_{i})$ better $f(X_{k})$?

Please tell me what is the problem?




     \State initialize no of students, no of subjects i.e., variables, termination criteria

     \State Calculate the mean of each variable or subjects

       \State Find the best solution and best variable value

      \While Stopping condition not met

    \For {for each learner X, of the class} %Teaching phase}

         \State $TeachingPhase=round(1+rand(0, I))$

         \For j=1:D

           \State $newX_{ij} = X_{ij} + rand(0, 1) \ast (Teacher(j)-TeachingPhase \ast Mean(j)$


            \State Accept $newX_{i} if f(newX_{i}) is better than f(X_{i})$


      \For each learner $X_{i}$ of the class % Learning phase

       \State  Randomly select one learner $X_{k}$, such that $i \neq k$

         \IF $f(X_{i})$ better $f(X_{k})$

             \For $j= 1:D$

             \State    $newX_{ij} =X_{ij}+rand(0, 1) \ast (X_{ij}-X_{kj})$



             \For $j= 1:D$

             \State    $newX_{ij}$ = $X_{ij}$+rand(0, 1) $\ast$ $(X_{kj}-X_{ij})$



        \State Accept $newX_{i}$ if $f(newX_{i})$ is better than $f(X_{i})$


     \State Update the Teacher and the Mean




  • 2
    You have to write \If instead of \IF. – Marcel Krüger Mar 26 '18 at 8:03

Your Answer

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

Browse other questions tagged or ask your own question.