MATLAB: Hybrid Scheme in the Genetic Algorithm.

genetic algorithmoptimization

Why doesn't neither of the following codes compile?
function genetic()
FitnessFcn = @dejong2fcn;
numberOfVariables = 2;
options = optimoptions(@ga,'PlotFcns',{@gaplotbestf,@gaplotstopping});
rng('default');
ga(FitnessFcn,numberOfVariables,[],[],[],[],[],[],[],options);
end
.
function hybrid()
fminuncOptions = optimoptions('Display','iter','Algorithm','quasi-newton');
options = optimoptions('HybridFcn',{@fminunc, fminuncOptions});
options = optimoptions(options,@ga,'PlotFcns',{@gaplotbestf,@gaplotstopping});
ga(@dejong2fcn,numberOfVariables,[],[],[],[],[],[],[],options);
end
I have written that code just like the following documentation.
Then, what is the issue?

Best Answer

First one:
Undefined function or variable 'dejong2fcn'.
Second one: you have not properly passed the solver names in.
fminuncOptions = optimoptions(@fminunc,'Display','iter','Algorithm','quasi-newton');
options = optimoptions(@ga,'HybridFcn',{@fminunc, fminuncOptions});
options = optimoptions(options,'PlotFcns',{@gaplotbestf,@gaplotstopping});