File Exchange

image thumbnail

Basic Genetic Algorithm

version (5.52 KB) by Xavier Blasco
An easy to use Genetic Algorithm


Updated 10 May 2018

View License

These scritps implement the version of the Genetic Algorithm decribed in
"Control predictivo basado en modelos mediante técnica de optimización heurística. Aplicación a procesos no lineales y multivariables. F. Xavier Blasco Ferragud. PhD Tesis 1999 (in Spanish). Editorial UPV. ISBN 84-699-5429-6.
It is an easy to use GA and basic instructions are supplied.
Available at:

Comments and Ratings (23)


Thank you for your answer, I have a problem in the process of my own changes, and now I have solved

Answer to xi:

If you define a function of 1 parameter.
function value=objfun_y(x)

And execute:
gaDat.FieldD=[lb; ub];

it works.

If you define the function as a 4 parameter function:
function value=objfun_y4(x)

and execute:
lb=[-1 -1 -1 -1];
ub=[1 1 1 1];
gaDat.FieldD=[lb; ub];
% Execute GA

It also works. I don't understand what is the problem.


I want to use this code to solve a quaternary equation, how should I modify it? for example y=x(1)^2+sin(x(2))+3*x(3)+x(4)^3-1. When I modified the target parameters. After modifying the upper and lower limits of the parameter, it still cannot be solved. the error in function chrom=crtrp(Nind,FieldDR);

Ranran Xu

Islam Samy

please, i want to the code og genetic algorithm with the fitness function

Xavier Blasco

Answer to Mehdi Elkaddouri
I can't reproduce the error. I suppose your are running example.m, but everything works well when I run it. Your comment suggest me you you don't have executed the line 1 to 4 of the example or you have delete the variable gaDat before executing line 5.

Undefined function or variable 'gaDat'.

Error in ga (line 5)
gaDat=ga(gaDat) how could i pass this error ?

hello Xavier thank you so much for the code, my problem is to maximize the power of PV system using genetic algorithm.thank you so much

Burak Ersin

Burak Ersin

Answer to Lydia Hamis.
You have to build a cost function for your problem. There is a short tutorial where you can see examples of use.

lydia hamis

My study regarding image reconstruction using constrained least squares filter. In order to get better result, i would like to implement GA. How do i implement this code to the current results?


Harry Smith

Thanks for the code, quick conversion from Matlab solver GA to yours

Answer to Jaouadi Zouhour.
No heuristic algorithm can guarantee to have found the global optimum. In the current version of the algorithm the stop is done with a fixed number of iterations, but the user can add his own criterion of stop in the function gaiteration.m. This function is executed at each iteration of the algorithm.
For instances, you could add:
if yourStopCriterionIsSatisfied
Change yourStopCriterionIsSatisfied by your own condition.

Thank you for the code.
I have a question, While applying the ga alg. my optimal function converges to a fix value starting from an iteration (iteration: 50). does it correspond to the optimal point? is it possible to stop the iterations and assume it as the minimum ?

Ahmad wali

New SLM scheme to reduce the PAPR of OFDM signals using
a genetic algorithm


Correcting the order in the way each the gaiteration is performed.
Minor bug fix in the introductions of individuals at the initial population.

Bug fixed. Improved code efficiency.

MATLAB Release Compatibility
Created with R2009b
Compatible with any release
Platform Compatibility
Windows macOS Linux