Professional Documents
Culture Documents
Study of
MATLAB
CONTENT
DC motor armature
control..1-4
Introduction to Genetic
Algorithm4-8
Study of Genetic Algorithm using
MATLAB...9-18
TRANSFER FUNCTION
For controlling the speed of the motor by varying the applied voltage. The
speed vs time graph of feeding the software with a transfer function obtained by
taking the speed as output and applied voltage as input. And the syntax LTIview
is used.
If the change in speed with other variable, the appropriate transfer function
has to be taken with the desired variable as input.
Example:
In this example, Im taking two transfer functions, one with speed as output
and other with position as output, while both of them have applied voltage as input.
>> R=2;
1
>> L=0.5;
>> Fo=0.1;
>> Kb=0.1;
>> Kt=0.2;
>> J=0.02;
>> h=tf(Kt,[L*J (R*J)+(Fo*L) (R*Fo)+(Kt*Kb)
h=
0.2
-----------------------0.01 s^2 + 0.09 s + 0.22
GENETIC ALGORITHM
As early as 1962, John Holland's work on adaptive systems laid the
foundation for later developments.
By the 1975, the publication of the book
Early to mid-1980s, genetic algorithms were being applied to a broad range of
subjects.
In 1992 John Koza has used genetic algorithm to evolve programs to perform
certain tasks. He called his method "genetic programming"(GP).
What is a Genetic Algorithm??
A genetic algorithm (or GA) is a search technique used in computing to find true
or approximate solutions to optimization and search problems.
4
VOCABULARY
Individual - Any possible solution
Population - Group of all individuals
EXAMPLE
Suppose we want to maximize the number of ones in a string of l
binary digits
Is it a trivial problem?
It may seem so because we know the answer in advance
However, we can think of it as maximizing the number of correct answers,
each encoded by 1, to l yes/no difficult questions.
An individual is encoded (naturally) as a string of l binary digits
The fitness f of a candidate solution to the MAXONE problem is the number of
ones in its genetic code
We start with a population of n random strings. Suppose that l = 10 and n = 6.
We toss a fair coin 60 times and get the following initial population:
s1 = 1111010101 f (s1) = 7
s2 = 0111000101 f (s2) = 5
s3 = 1110110101 f (s3) = 7
s4 = 0100010011 f (s4) = 4
s5 = 1110111101 f (s5) = 8
s6 = 0100110000 f (s6) = 3
STEP 1: SELECTION
We randomly (using a biased coin) select a subset of the individuals based on their
fitness:
Suppose that, after performing selection, we get the following population:
s1` = 1111010101 (s1)
s2` = 1110110101 (s3)
s3` = 1110111101 (s5)
6
STEP 3: MUTATION
The final step is to apply random mutations: for each bit that we are to copy to the
new population we allow a small probability of error (for instance 0.1)
Initial strings
After mutating
s1`` = 1110110101
s1``` = 1110100101
s2`` = 1111010101
s2``` = 1111110100
s3`` = 1110111101
s3``` = 1110101111
s4`` = 0111000101
s4``` = 0111000101
s5`` = 0100011101
s5``` = 0100011101
s6`` = 1110110011
s6``` = 1110110001
At this point, we go through the same process all over again, until a stopping
criterion is met
There are many different strategies to select the individuals to be copied over into
the next
Generation
Methods of Selection
1.
2.
3.
4.
5.
Roulette-wheel selection.
Elitist selection.
Fitness-proportionate selection.
Scaling selection.
Rank selection.
Genetic algorithm in
MATLAB
MATLAB has the option of solving problems using different optimization
tools like: bintprog, fgoalattain, fminbnd, fmincon, fminimax, fminsearch,
fminunc, fseminf, fsolve, fzero, and Genetic Algorithm procedures. MATLAB
offers syntaxes as well as tool box for using GA. Every parameter related to the
GA while solving the problem could be set customized, and desired values can be
set. Thought it is well known for its simplicity, GAs can be made even more
effective by and can be made apt for solving various problems by placing suitable
values for parameters like Population, Fitness scaling, Selection, Reproduction,
Mutation, Crossover, Migration, Constraint parameters, Hybrid function, Stopping
criteria, Plot functions, Output function, Display to command window, User
function evaluation.
The
population of
the genetic
algorithm could
be set as desired.
It sould be noted
that high value
of initial
poplation though
helpful for more
accurate
solution, it leads
to too many
calculations. While
low population
leads to very low
accurate solution.
Sometimes the
fittest solution of
one generation
might be the best solution. By blindly involving it in crossover there may be
wastage of
solution. So to stop
the loss of such
solutions, the
fittest solution in
each generation is
kept aside from crossover. The number of chromosomes that should be spared from
crossover is selected by elite count.
11
12
There are many reason for GA to come to end. We can set few of the
parameters that involve the halting of Genetic Algorithm. We can limit the number
of generations,
time, minimum
fitness required.
13
Examples:
14
15
Example:
Feed the software with the function through editor, whose minimum value
has to be identified. Here the function is:
Y = x^2
By setting different values of the GA parameters solution is found out.
16
17
The solution obtained is 0. While the value of the function at final point is
4.33403588142492E-10, and the reason for halting is average change in the fitness
value less than options.
Or the simply the minimum of the function could be found by using the syntax
ga.
Example:
>> [x,fval,exitflag]=ga(@test,1)
Optimization terminated: average change in the fitness value less than
options.TolFun.
x=
0.0122
fval =
1.4972e-04
exitflag =
1
@test is our function. Which should be given through editor.
1 is the number of variables.
x is the indicates the final point.
Fval is the value of the value of function at x.
Exitflag is the reason for the halting of the process.
18
19