Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Function optimization of genetic algorithm based on matlab
Function optimization of genetic algorithm based on matlab
With ga function, ga function is a function of genetic algorithm, and its calling format is:

x

=

ga(fitnessfcn、nvars、a、b、aeq、beq、lb、ub、nonlcon、options)

Fitnessfcn is the function to be optimized, nvars is the number of variables, and then the following lb is the lower bound and ub is the upper bound. This problem requires the parameters of these four positions, and the parameters of other positions can be replaced by []. Because the default of ga function is to find the minimum value of the function to be optimized, in order to find the maximum value, the function to be optimized needs to be negative, that is, written as

function

y=myfun(x)

y=-x.*sin( 10*pi。 * x)-2;

Save this function as myfun.m, and then type it on the command line.

x=ga(@myfun, 1,[],[],[],[],[ 1],[2])

Will come back.

optimization

Terminated:

Average

change

exist

this

health

value

fewer/ lesser

compare

options.tolfun。

x

=

1.8506

Because the principle of genetic algorithm is to randomly select the initial value within the range of values, and then inherit it, so each run may give different values, for example, it will return after another run.

optimization

Terminated:

Average

change

exist

this

health

value

fewer/ lesser

compare

options.tolfun。

x

=

1.6507

This specific reason needs to refer to the relevant information of genetic algorithm.