2

I am writting my thesis and really like to be able to make some equations like the one shown in the picture but don't know how. Your help is really appreciated.

https://towardsdatascience.com/particle-swarm-optimization-visually-explained-46289eeb2e14e

Image taken from : https://towardsdatascience.com/particle-swarm-optimization-visually-explained-46289eeb2e14

4

1 Answer 1

5

Here is my attempt with tikz:

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usepackage{amsmath}
\tikzset{mystyle/.style={minimum height=2cm,rounded corners=3mm,anchor=base,
label={[anchor=south]south:{\scriptsize\bfseries\textsf{#1}}}}}
\begin{document}
\[
\begin{aligned}
P_i^{t+1} &= P_i^t+V_i^{t+1}\\
V_i^{t+1} &=
\tikz[baseline]{
    \node[fill=gray!20,mystyle=Inertia\strut] (t1)
    {$w V_i^t$}} + 
\tikz[baseline]{
    \node[fill=magenta!20,mystyle=Cognitive(Personal)] (t2)
    {$c_1 r_1\left(P_{best(i)}^t - P_i^t\right)$}} + 
\tikz[baseline]{
    \node[fill=teal!20,mystyle=Social(Global)] (t3)
    {$c_2 r_2\left(P_{bestglobal}^t-P_i^t\right)$}}
\end{aligned}
\]
\end{document}

enter image description here

3
  • Wow, perfect! Let me say thank you very much! Mar 4 at 14:17
  • 1
    @Andrey L. For vertical alignment of labels, I suggest putting \strut, not only for Inertia but in the command after \textsf{#1}
    – pascal974
    Mar 5 at 12:39
  • @pascal974, thanks, that's a good point.
    – Andrey L.
    Mar 5 at 13:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .