gn="justify">
Додаток Текст програми
Файл a2.m
=20;=2;% число змінних x
(1)=- 30; (1)=30; (2)=- 10; (2)=10;
% побудова графіка функції 2-х змінних
if nvars == 2=(Xmax (1) - Xmin (1))/49;=(Xmax (2) - Xmin (2))/49;=Xmin (1): dx1:Xmax (1);=Xmin (2): dx2: Xmax (2);=length (x1);=length (x2); i=1: 1: n1j=1: 1: n2 (i, j)= 2 * x1 (i) ^ 2-4 * x1 (i) ^ 4 + 1/2 * x1 (i) ^ 6 + x1 (i) ^ 2 * x2 (j) ^ 2; (x1, x2, Y) , grid on; ( x1 ); ( x2 ); ( f (x) );
i1=1: 1: 5i11, =selectionremainder; 2, =selectionuniform; 3, =selectionstochunif; 4, =selectionroulette; 5, =selectiontournament;=[Xmin; Xmax];=gaoptimset;=gaoptimset (options, PopInitRange raquo ;, PIR);=gaoptimset (options, PopInitRange raquo ;, []);=gaoptimset (options, PopulationSize raquo ;, 100);=gaoptimset (options , EliteCount raquo ;, 5);=gaoptimset (options, CrossoverFraction raquo ;, 0.8);=gaoptimset (options, ParetoFraction raquo ;, 0.05);=gaoptimset (options, MigrationDirection raquo ;, both ) ;=gaoptimset (options, MigrationInterval raquo ;, 1);=gaoptimset (options, MigrationFraction raquo ;, 1);=gaoptimset (options, Generations raquo ;, 100);=gaoptimset (options, TimeLimit raquo ;, 400);=gaoptimset (options, FitnessLimit raquo ;, - Inf);=gaoptimset (options, StallGenLimit raquo ;, 50);=gaoptimset (options, StallTimeLimit raquo ;, 600);=gaoptimset (options, TolFun raquo ;, 1e - 6);=gaoptimset (options, TolCon raquo ;, 1e - 6);=gaoptimset (options, InitialPopulation raquo ;, []);=gaoptimset (options, InitialScores raquo ;, []) ;=gaoptimset (options, InitialPenalty raquo ;, []);=gaoptimset (options, PenaltyFactor raquo ;, []);=gaoptimset (options, CreationFcn raquo ;,gacreationuniform);=gaoptimset (options, FitnessScalingFcn raquo ;,fitscalingrank);=gaoptimset (options, SelectionFcn raquo ;, SF);=gaoptimset (options, CrossoverFcn raquo ;, {crossoverheuristic, 1.2});=gaoptimset (options, MutationFcn raquo ;,mutationadaptfeasible );=gaoptimset (options, DistanceMeasureFcn raquo ;, []);=gaoptimset (options, HybridFcn raquo ;, []);=gaoptimset (options, Display raquo ;, iter );=gaoptimset (options , PlotFcns raquo ;, {gaplotbestf});=gaoptimset (options, PlotInterval raquo ;, 1);
k=1: 1: N
[X (k, :), FVal (k)]=ga (@ ex95, nvars, [], [], [], [], Xmin, Xmax, [], options) ; (i1)=mean (FVal), j=1: 1: nvars_ (i1, j)=mean (X (:, j)); _ (i1,:),
(3); (1: 1: i1, F), grid on;
Файл ex95.m
y=ex95 (x) (1) ^ 2-12 * x (1) + 11 + 10 * cos (pi/2 * x (1)) + 8 * sin (5 * pi * x (1)) - 1/sqrt (5) * exp (- 1 * ((x (1) - 0.5) ^ 2)/2);
end