MATLAB: Genetic algorithm say ‘average change in the fitness value less than options.Fu​nctionTole​rance.’

genetic algorithm

I am studying 'Genetic algorithm'. I made 'y2' for optimizing with this function ' y = 100 * (a^2 – b) ^2 + (1 – a)^2 '.
Those are same things. like between y = a + 3 and y = 2 + 3. and i want to get a = 2. I thought this way 'sum((y-y2).^2)'.
But it doesn't work well saying ''average change in the fitness value less than options.FunctionTolerance.' The results are not good. I think the iteration is not enough to optimize . and it ends.
How could I solve this problem….
Thank you so much..
.
.
.
y2 = 100 * (1.5083^2 - 2.2781) ^2 + (1 - 1.5083)^2;
rng default % For reproducibility
FitnessFunction = @(a,b) simple_fitness(y2);
numberOfVariables = 2;
lb = [-3 -3];
ub = [3 3];
[x,fval] = ga(FitnessFunction,numberOfVariables,[],[],[],[],lb,ub)
function of = simple_fitness(y2)
a=1;
b=1;
y = 100 * (a^2 - b) ^2 + (1 - a)^2;
of = sum((y-y2).^2);
end

Best Answer

function of = simple_fitness(y2)
a=y2(1);
b=y2(2);
of = 100 * (a^2 - b) ^2 + (1 - a)^2;
end