Professional Documents
Culture Documents
Contoh Program
Contoh Program
clc
pop_awal = 1000; %number of population
next_pop = 1;
run = 1;
s = tf('s');
p_motor = 1/(s^2+3*s+2);
t=0:0.1:20;
for r =1 : run
index = 1;
for i = 1 :pop_awal
pop(index, 1 , 1) = 2*rand;
pop(index, 1 , 2) = 0.001*rand;
pop(index, 1 , 3) = 0.01*rand;
index = index +1;
end
fo=0; %referensi awal
for i = 1 :pop_awal
x = pop (i, 1, 1);
y = pop (i, 1, 2);
z = pop (i, 1, 3);
x_pop(i) = x; %kp
y_pop(i) = y; %ki
z_pop(i) = z; %kd
C = x + y/s + z*s;
RS = feedback (C * p_motor,-1);
y_out = step(RS,t);
err = 1 - y_out;
ea = abs (err);
IAE = sum(ea);
fit = 1 / ( 1+IAE);
if fit >fo
best_fit = fit;
fo = fit;
best_x = x;
best_y = y;
best_z = z;
end
fitness (i) = fit;
end
pop %populasi awal;
fitness' % fitness setiap populasu;
best_fit % fitness terbaik
best_x %individu terbaik
best_y
best_z
fo %