GADS命令方式求解非线性约束问题

求解问题

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+x3460;x1+x12+x225x3340;3x1+2x12+x2+3x3670;x1+x32=13;x10;x210;

主程序

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

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值