求解问题
m a x    2.2 x 1 + 3 x 2 + 4.5 x 3 + 3 x 1 2 + x 3 2 ;    4 x 1 2 + 2 x 2 2 + x 3 − 46 ≤ 0 ; x 1 + x 1 2 + x 2 2 − 5 x 3 − 34 ≤ 0 ; 3 x 1 + 2 x 1 2 + x 2 + 3 x 3 − 67 ≤ 0 ; x 1 + x 3 2 = 13 ; x 1 ≤ 0 ; x 2 ≤ 10 ; max \qquad \; 2.2x_{1}+3x_{2}+4.5x_{3}+3x_{1}^2+x_{3}^2;\\ \;\\ 4x_{1}^2+2x_{2}^2+x_{3}-46\leq0; \\ \qquad x_{1}+x_{1}^2+x_{2}^2-5x_{3}-34\leq0; \\ \qquad \quad 3x_{1}+2x_{1}^2+x_{2}+3x_{3}-67\leq0;\\ x_{1}+x_{3}^2=13;\\ x_{1}\leq0;x_{2}\leq10; max2.2x1+3x2+4.5x3+3x12+x32;4x12+2x22+x3−46≤0;x1+x12+x22−5x3−34≤0;3x1+2x12+x2+3x3−67≤0;x1+x32=13;x1≤0;x2≤10;
主程序
clc; clear;
myFitnessFun=@(x) -(2.2*x(1)+3*x(2)+4.5*x(3)+3*x(1)^2+x(3)^2);
A=[-2 -4 -6;-1 0 0;0 1 0];
b=[-10;0;10];
Aeq=[ ];
beq=[ ];
lb=[];
ub=[];
init_pop=repmat([3 1 3],100,1);
options=gaoptimset('InitialPopulation',init_pop,'CreationFcn',@gacreationlinearfeasible, ...
'PopulationType','doubleVector' ,'PopulationSize',100,'EliteCount',1,...
'CrossoverFraction',0.75,'Generations',100,'StallGenLimit',500,...
'TolFun',1e-100,'PlotFcns',{@gaplotbestf,@gaplotbestindiv}); %参数设置t;
[x_best,fval,reason,output,final_pop]=ga(myFitnessFun,3,A,b,Aeq,beq,ub,lb,@myNolinCon,options);
display(x_best);
fprintf('最优适应度值:%.3f\n',-fval);
myNolinCon函数
%ex4_2非线性约束
function [nlneq, nleq]=myNolinCon(x)
nlneq=[4*x(1)^2+2*x(2)^2+x(3)-46;
x(1)+x(1)^2+x(2)^2-5*x(3)-34;
3*x(1)+2*x(1)^2+x(2)+3*x(3)-67];
nleq=x(1)+x(3)^2-13;
end
结果
x_best =
3.1546 1.2363 3.1377
最优适应度值:64.469