x1+x2+x3=1,且x1,x2,x3>0,用matlab遗传算法工具箱求min(x1)^2+(x2)^2+(x3)^2+x1x2+x2x3+x1x3,求源代码啊

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/15 22:47:27
x1+x2+x3=1,且x1,x2,x3>0,用matlab遗传算法工具箱求min(x1)^2+(x2)^2+(x3)^2+x1x2+x2x3+x1x3,求源代码啊
xTO@WcD cL4 ծ| EKH&!F@ϴĿݵ.mvsoTS8)^j  Kml֐or+wZfv5><|OKTOqIB¾ XqG/QTzok[AMb>&O[l<7`\J<ӄXL}3M#q$s(R}#(g{PNΊޥ-^w?pSM`XYV0r2+Se~Y$M& *P) *`)rqs]J'XkڴkvC;kƒlxTˉȉq gq93^RS`[=bb$죛fց_XP8hupe3nF'WC®dש*rEǎwcYm'P. ,$\U,|l\ t놉 zՂ*lt`?_tf#Zx fױ/q^ Hnݟ^ FY5IjB|sJ;Vs

x1+x2+x3=1,且x1,x2,x3>0,用matlab遗传算法工具箱求min(x1)^2+(x2)^2+(x3)^2+x1x2+x2x3+x1x3,求源代码啊
x1+x2+x3=1,且x1,x2,x3>0,用matlab遗传算法工具箱求min(x1)^2+(x2)^2+(x3)^2+x1x2+x2x3+x1x3,求源代码啊

x1+x2+x3=1,且x1,x2,x3>0,用matlab遗传算法工具箱求min(x1)^2+(x2)^2+(x3)^2+x1x2+x2x3+x1x3,求源代码啊
M文件:
function [c,ceq] = eqCon(x)
c = [];
ceq = [x(1)+x(2)+x(3)-1];
M文件:
function z = my_fun(x)
z = (x(1))^2+(x(2))^2+(x(3))^2+x(1)*x(2)+x(2)*x(3)+x(1)*x(3);
在matlab命令窗口中输入:
close all
clear,clc
[x,fval] = ga(@my_fun,3,[],[],[],[],[0 0 0],[],@eqCon)

用Lingo求解比较方便
用Lingo求
min=x1*x1+x2*x2+x3*x3+x1*x2+x2*x3+x1*x3;
x1+x2+x3=1;
x1>0;
x2>0;
x3>0;
Local optimal solution found.
Objective value: ...

全部展开

用Lingo求解比较方便
用Lingo求
min=x1*x1+x2*x2+x3*x3+x1*x2+x2*x3+x1*x3;
x1+x2+x3=1;
x1>0;
x2>0;
x3>0;
Local optimal solution found.
Objective value: 0.6666667
Extended solver steps: 5
Total solver iterations: 30
Variable Value Reduced Cost
X1 0.3333333 0.000000
X2 0.3333333 0.000000
X3 0.3333333 0.000000
Row Slack or Surplus Dual Price
1 0.6666667 -1.000000
2 0.000000 -1.333333
3 0.3333333 0.000000
4 0.3333333 0.000000
5 0.3333333 0.000000

收起