Matlabga forming
For example, using the idea of genetic algorithm in MATLAB, we can solve f (x) = x * sin (10pi * x)+2.0,-1

First, enter f = @ (x)-(x * sin (10 * pi * x)+2) in the matlab command window, and the output result is as follows.

& gt& gtf=@(x)-(x*sin( 10*pi*x)+2)

f =?

@(x)-(x*sin( 10*pi*x)+2)

Then enter gatool to open the genetic algorithm toolbox.

Set up as shown above, and then click Start.

The running results are as follows

The algorithm is terminated after 5 1 generation, and the minimum result is -3.85027347 19567, and the corresponding x is 1.85 1. Because the user-defined function is added with a negative sign, the maximum value of the original formula is 3.85027 19567, which corresponds to.

But this is the result of genetic algorithm, and the result of each operation may be different, not necessarily the exact maximum.

Genetic algorithm is suitable for some complex problems (conventional algorithm takes too long to solve).