Sie sind auf Seite 1von 8

Experiment No:TITLE:-Study of MATLAB.

AIM:-Study of Genetic Algorithm application used in MATLAB.

THERORY:1. MATLAB:MATLAB is a high-performance language for technical computing. It
integratescomputation, visualization, and programming in an easy-to-use environmentwhere
problems and solutions are expressed in familiar mathematical notation.
1.1 Typical uses include

Math and computation

Algorithm development
Data acquisition
Modeling, simulation, and prototyping
Data analysis, exploration, and visualization
Scientific and engineering graphics
Application development, including graphical user interfacebuilding

MATLAB is an interactive system whose basic data element is an array that does not
require dimensioning. This allows you to solve many technicalcomputing problems, especially
those with matrix and vector formulations,in a fraction of the time it would take to write a
program in a scalar noninteractivelanguage such as C or Fortran.The name MATLAB stands for
matrix laboratory. MATLABwas originally written to provide easy access to matrix software
developedby the LINPACK and EISPACK projects. Today, MATLAB engines incorporate
theLAPACK and BLAS libraries, embedding the state of the art in software formatrix
computation. MATLAB has evolved over a period of years with input from many users.In
university environments, it is the standard instructional tool for introductoryand advanced
courses in mathematics, engineering, and science. In industry,MATLAB is the tool of choice for
high-productivity research, development,and analysis. MATLAB features a family of add-on
application-specific solutions called toolboxes.Very important to most users of MATLAB,
toolboxes allow you to learn and apply specializedtechnology. Toolboxes are comprehensive
collections of MATLAB functions (M-files)that extend the MATLAB environment to solve
particular classes of problems.Areas in which toolboxes are available include signal processing,
controlsystems, neural networks, fuzzy logic, wavelets, simulation, and many others.

1.2 The MATLAB System:The MATLAB system consists of these main parts:

Desktop Tools and Development EnvironmentThis is the set of tools and facilities that help you use MATLAB functions and
files. Many of these tools are graphical user interfaces. It includes the MATLAB desktop
and Command Window, a command history, an editor and debugger, a code analyzer and
other reports, and browsers for viewing help, the workspace, files, and the search path.


The MATLAB Mathematical Function LibraryThis is a vast collection of computational algorithms ranging from elementary
functions, like sum, sine, cosine, and complex arithmetic, to more sophisticated functions
like matrix inverse, matrix eigenvalues, Bessel functions, and fast Fourier transforms.


The MATLAB LanguageThis is a high-level matrix/array language with control flow statements, functions,
data structures, input/output, and object-oriented programming features. It allows both
"programming in the small" to rapidly create quick and dirty throw-away programs, and
"programming in the large" to create large and complex application programs.


GraphicsMATLAB has extensive facilities for displaying vectors and matrices as graphs,
as well as annotating and printing these graphs. It includes high-level functions for twodimensional and three-dimensional data visualization, image processing, animation, and
presentation graphics. It also includes low-level functions that allow you to fully
customize the appearance of graphics as well as to build complete graphical user
interfaces on your MATLAB applications.

1.3 MATLAB DocumentationMATLAB provides extensive documentation, in both printable and HTML format, to
help you learn about and use all of its features. If you are a new user, start with this Getting
Started book. It covers all the primar MATLAB features at a high level, including many
To view the online documentation, select MATLAB Help from the Help menu in
MATLAB. Online help appears in the Help browser, providing task-oriented and reference
information about MATLAB features. For more information about using the Help browser,
including typographical conventions used in the documentation.

The MATLAB documentation is organized into these main topics:

Desktop Tools and Development Environment Startup and shutdown, the

desktop, and other tools that help you use MATLAB.

Mathematics Mathematical operations.

DataAnalysis Data analysis, including data fitting, Fourier analysis,and timeseries tools.
Programming The MATLAB language and how to develop MATLAB
Graphics Tools and techniques for plotting, graph annotation, printing, and
programming with Handle Graphics 3-D.
Visualization Visualizing surface and volume data, transparency,and viewing
and lighting techniques.
CreatingGraphical User Interfaces GUI-building tools and how to
writecallback functions External.
Interfaces MEX-files, the MATLAB engine, and interfacingto Java, COM,
and the serial port.

MATLAB also includes reference documentation forall MATLAB functions:

Functions By Category Lists all MATLAB functions grouped into

Handle GraphicsProperty Browser Provides easy access to descriptions
ofgraphics object properties.
Cand Fortran API Reference Covers those functionsused by the MATLAB
external interfaces, providing information on syntax inthe calling language,
description, arguments, return values, and examples.

The MATLAB onlinedocumentation also includes :

Examples An index of examples included in the documentation.

ReleaseNotes New features, compatibility considerations, and bugreports.`
Printable Documentation PDF versions of the documentation suitable for
In addition to the documentation, you can access demos from the Helpbrowser by
clicking the Demos tab. Run demos tolearn about key functionality of Math Works products and

2. Genetic AlgorithmThe genetic algorithm is a method for solving both constrained and
unconstrainedoptimization problems that is based on natural selection, the process thatdrives
biological evolution. The genetic algorithm repeatedly modifies a populationof individual
solutions. At each step, the genetic algorithm selects individualsat random from the current
population to be parents and uses them to producethe children for the next generation. Over

successive generations, the population"evolves" toward an optimal solution. You can apply the
genetic algorithmto solve a variety of optimization problems that are not well suited for
standardoptimization algorithms, including problems in which the objective functionis
discontinuous, nondifferentiable, stochastic, or highly nonlinear.
The genetic algorithm uses three main types of rules at each step tocreate the next generation
from the current population Selection rules select the individuals,called parents, that contribute to the population atthe
next generation.
Crossover rules combine two parents toform children for the next generation.
Mutation rules apply random changes toindividual parents to form children.
The genetic algorithm differs from a classical, derivative-based, optimizationalgorithm
2.1 Calling the Function ga at the Command LineTo use the genetic algorithm at the command line, call the genetic algorithmfunction ga with the
[xfval] = ga(@fitnessfun, nvars, options)
@fitnessfun is a handle to the fitnessfunction.
nvars is the number of independent variablesfor the fitness function.
options is a structure containing optionsfor the genetic algorithm.If you do not pass in
this argument, ga usesits default options.
The results are given
byx Point at which the final valueis attained
fval Final value of the fitnessfunction
Using the function ga is convenient if you wantto
Return results directly to the MATLAB workspace
Run the genetic algorithm multiple times with different options,by calling ga from an Mfile

Figure 1 : Opening Window of Matlab

Figure 2 :Open Demos-Genetic Algorithm-Custom data type optimization

Figure 3 :Opening Coding window of example

3. Coding :load('usborder.mat','x','y','xx','yy');
plot(x,y,'color','green'); hold on;
cities = 10;
locations = zeros(cities,2);
n = 1;
while (n <= cities)
xp = rand*1.5;
yp = rand;
locations(n,1) = xp;
locations(n,2) = yp;
n = n+1;
distances = zeros(cities);
for count1=1:cities,
for count2=1:count1,
x1 = locations(count1,1);
y1 = locations(count1,2);
x2 = locations(count2,1);
y2 = locations(count2,2);

FitnessFcn = @(x) traveling_salesman_fitness(x,distances);
my_plot = @(options,state,flag) traveling_salesman_plot(options, ...
options = gaoptimset('PopulationType', 'custom','PopInitRange', ...
options = gaoptimset(options,'CreationFcn',@create_permutations, ...
'CrossoverFcn',@crossover_permutation, ...
'MutationFcn',@mutate_permutation, ...
'PlotFcn', my_plot, ...
'Generations',500,'PopulationSize',60, ...
numberOfVariables = cities;
[x,fval,reason,output] = ga(FitnessFcn,numberOfVariables,options)

Figure 4 :Coding of Program

Figure 5 :After running it shows the map of Program

Figure 6 :Output Window