**5.2 PSO algorithm demo with one example**

Objective function used for Minimization:

$$Fitness = 10 \ast (X\_1 - 1) \text{"2} + 20 \ast (X\_2 - 2) \text{"2} + 30 \ast (X\_3 - 3) \text{"2}$$

**STEP – 1: PARAMETERS INITIALIZATION** (**Table 2**)**: Number of variables:** *m = 3.* **Population size:** *n = 5.* **Inertia weight:** *Wmax = 0.9, Wmin = 0.4.*


**Table 2.** *Output [5].* *Particle Swarm Optimization DOI: http://dx.doi.org/10.5772/intechopen.107156*

**Acceleration Factor:** *C1 = 2, C2 = 2.* **Maximum Iteration:** *Maxiter = 50.* **% Population Initialization** *LB = [0 0 0]; UB = [10 10 10]; for i = 1: n for j = 1:m X0 (i, j) = round (LB (j) + rand () \* (UB (j) – LB (j))); end end*

• **Initialize velocity (***vi***) randomly for each particle:** (**Table 3**)

```
• v = 0.1 * X0 (i, j);
```

```
Initial velocity for First Particle:
v(X1) = 0.1 * 8 = 0.8
v(X3) = 0.1 * 9 = 0.9
v(X1) = 0.1 * 1 = 0.1
Initial velocity for Second Particle:
v(X1) = 0.1 * 9 = 0.9
v(X3) = 0.1 * 6 = 0.6
v(X1) = 0.1 * 1 = 0.1
Initial velocity for Third Particle:
v(X1) = 0.1 * 3 = 0.3
v(X3) = 0.1 * 5 = 0.5
v(X1) = 0.1 * 10 = 1.0
Initial velocity for Fourth Particle:
v(X1) = 0.1 * 10 = 1.0
v(X3) = 0.1 * 2 = 0.22
v(X1) = 0.1 * 10 = 1.0
Initial velocity for Fifth Particle:
v(X1) = 0.1 * 10 = 1.0
v(X3) = 0.1 * 5 = 0.5
v(X1) = 0.1 * 8 = 0.8
Initial Position (Xi) Randomly for each Particles (Table 4):
Current Position = Previous Position + Velocity
Current Position for First Particle:
X1 = 8 + 0.8 = 8.8
```


**Table 3.** *Initial population [5].*


**Table 4.**

*Initial velocity [5].*

*X2 = 9 + 0.9 = 9.9 X3 = 1 + 0.1 = 1.1 Current Position for Second Particle: X1 = 9 + 0.9 = 9.9 X2 = 6 + 0.6 = 6.6 X3 = 1 + 0.1 = 1.1 Current Position for Third Particle: X1 = 3 + 0.3 = 3.3 X2 = 5 + 0.5 = 5.5 X3 = 10 + 1 = 11 Current Position for Fourth Particle: X1 = 10 + 1 = 11 X2 = 2 + 0.2 = 2.2 X3 = 10 + 1 = 11 Current Position for Fifth Particle: X1 = 10 + 1 = 11 X2 = 5 + 0.5 = 5.5 X3 = 8 + 0.8 = 8.8* **STEP – 2: FITNESS EVALUATION** *f xt i* (**Table 5**) *Fitness Evaluation for Every Particle: The objective function taken for minimization:*

$$F(\mathbf{x}) = \mathbf{10} \* (X\_1 - \mathbf{1})^\prime 2 + 2\mathbf{0} \* (X\_2 - \mathbf{2})^\prime 2 + 3\mathbf{0} \* (X\_3 - \mathbf{3})^\prime 2$$

$$F(\mathbf{x}\_1^0) = \mathbf{10} \* (8.8 - \mathbf{1})^\prime 2 + 2\mathbf{0} \* (9.9 - \mathbf{2})^\prime 2 + 3\mathbf{0} \* (\mathbf{1.1} - \mathbf{3})^\prime \mathbf{2}$$

$$F(\mathbf{x}\_1^0) = \mathbf{1.9649}$$


**Table 5.** *Current position [5].*

$$F(\mathbf{x}\_2^0) = 10 \ast (9.9 - 1)^\prime 2 + 20 \ast (6.6 - 2)^\prime 2 + 30 \ast (11 - 3)^\prime 2$$

$$F(\mathbf{x}\_2^0) = 1.3236$$

$$F(\mathbf{x}\_3^0) = 10 \ast (3.3 - 1)^\prime 2 + 20 \ast (5.5 - 2)^\prime 2 + 30 \ast (11 - 3)^\prime 2$$

$$F(\mathbf{x}\_3^0) = 2.2179$$

$$F(\mathbf{x}\_4^0) = 10 \ast (11 - 1)^\prime 2 + 20 \ast (2.2 - 2)^\prime 2 + 30 \ast (11 - 3)^\prime 2$$

$$F(\mathbf{x}\_4^0) = 2.9208$$

$$F(\mathbf{x}\_5^0) = 10 \ast (11 - 1)^\prime 2 + 20 \ast (5.5 - 2)^\prime 2 + 30 \ast (8.8 - 3)^\prime 2$$

$$F(\mathbf{x}\_5^0) = 2.2542$$

*gBest = 1.3236* (**Table 6**)
