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

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/17 05:54:35

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

收起