You are on page 1of 3

Expt no:

Date:
OBTAINING CONTROLLER PARAMETERS USING GA Function IN MATLAB

Aim:
To obtain appropriate controller parameters for a process, satisfying an objective
function (eg. Minimum Integral square error) using genetic algorithm in Matlab.

Softwares Required: Matlab

Theory:

X = GA(FITNESSFCN,NVARS)
finds a local unconstrained minimum X to the FITNESSFCN using GA. NVARS is the dimension
(number of design variables) of the FITNESSFCN. FITNESSFCN accepts a vector X of size 1-by-
NVARS, and returns a scalar evaluated at X.

The following outline summarizes how the genetic algorithm works:
1. The algorithm begins by creating a random initial population.

2. The algorithm then creates a sequence of new populations. At each step, the algorithm uses
the individuals in the current generation to create the next population. To create the new
population, the algorithm performs the following steps:
a. Scores each member of the current population by computing its fitness value.
b. Scales the raw fitness scores to convert them into a more usable range of values.
c. Selects members, called parents, based on their fitness.
d. Some of the individuals in the current population that have lower fitness are chosen
as elite. These elite individuals are passed to the next population.
e. Produces children from the parents. Children are produced either by making random
changes to a single parentmutationor by combining the vector entries of a pair of
parentscrossover.
f. Replaces the current population with the children to form the next generation.

The algorithm stops when one of the stopping criteria is met.

Code:

functionsq = gen(k)
T=0.1;
B=1;
K=1;
F(1)=0;
sp=4;
Kp=k(1);
Ki=k(2);
Kd=k(3);
temp=0;
e=0;
pv=0;
m=0;
sq=0;
for t = 2:100
e(t)=sp-pv(t-1);
sq=sq+(e(t).*e(t));
temp=temp+e(t);
u(t)=Kp.*e(t)+Ki.*temp+Kd.*(e(t)-e(t-1))./T;
F(t)=u(t);
pv(t)=pv(t-1)+T.*(F(t)-K.*pv(t-1))./B;
m(t)=t*T;
end
plot(m,pv,'b');
end

Procedure:

1. Type the above code in an editor file and save it as fourth.m
2. In the command window type the following:
x=ga(@fourth,3)
3. Note down the values displayed. These are the controller parameters kp, ki, kd for
minimum integral square error.
8.6698 1.0104 0.0158
4. Evaluate the process output for the obtained controller parameters and plot the graph.

Output:

Fig. process output vs. time

Inference:
The ga produces different output at each compilation because of varying initial
assumptions. However, the obtained controller parameters satisfy the requirement.

Result:
Hence the controller parameters obtained for the given process is:
Kp = 8.6698
Ki = 1.0104
Kd = 0.0158
The integral square error for the above values is 16.0084