Expert Answer:
:
The main problem is that you don't understand how the toolbox works. You should refer to the documentation to get the whole idea.
So, the fitness function should be a function handle and should return a scalar.
fitnessfcn
Handle to the fitness function. The fitness function should accept a row vector of length nvars and return a scalar value.
First, your function is not well defined. If you want to define an anonymous function you should
parabola = @(x) prod(x);
optGA = gaoptimset('PlotFcns', @gaplotbestfun, 'PlotInterval', 10, 'PopInitRange', [-10 ; 10]);
[Xga,Fga] = ga(parabola,2,optGA)
The same can be achieved with the GUI of GA. In case you want to define your function in an m
file you should have something like:
parabola.m
function [y] = parabola(x)
y = prod(x);
And you define the handle like fh = @parabola
. And in the code above you replace parabola
for the new handle, fh
.
I hope this help you get started.