Skip to content

Instantly share code, notes, and snippets.

@shenbennwdsl
shenbennwdsl / gago.m
Created January 25, 2016 04:29
a genetic algorithm function in MATLAB
function [ fvalOfElite, xVal ] = gago( fun, valMin, valMax, tolerance, popSize, generationsNum, crossProb, mutateProb )
%GAGO genetic algorithm
%
% output:
% fvalOfElite: the minimum of the function
% xVal: the point that the function gets the minimum
%
% input:
% fun: the name of the function, e.g. 'afunc'
% valMin: the low limitation of the variables, e.g. [-10,-pi]