用matlab求解一个优化问题(目标函数非线性,约束函数线性)

minf(x)=12*x(1)+21*x(2)+21*x(3)+13*x(4)+20*x(5)+23*x(6)+15*x(7)+17*x(8)+27*x(9)+17*x(... min f(x)=12*x(1)+21*x(2)+21*x(3)+13*x(4)+20*x(5)+23*x(6)+15*x(7)+17*x(8)+27*x(9)+17*x(10)+19*x(11)+31*x(12)+200*[(x(1)+x(2)+x(3))^0.6+(x(4)+x(5)+x(6))^0.6+(x(7)+x(8)+x(9))^0.6+(x(10)+x(11)+x(12))^0.6]
s.t. x(1)+x(2)+x(3)<=183.55;
x(4)+x(5)+x(6)<=283.55;
x(7)+x(8)+x(9)<=383.55;
x(10)+x(11)+x(12)<=183.55;
x(1)+x(4)+x(7)+x(10)>=116.45;
x(2)+x(5)+x(8)+x(11)>=316.45;
x(3)+x(6)+x(9)+x(12)>=416.45;
x(1),…x(12)>=0;
我是这样求的:
目标函数(运行显示下标不对)
function f=myobj(x)
c = [12 21 21; 13 20 23; 15 17 27; 17 19 31];
size(x) = [4,3];
y = c.*x;
y = sum(y(:));
s = 0;
for i = 1:4
sg = sum(x(i,:));
s = s+sg^0.6;
end
f = y+200*s;
command window
A= [1,1,1,0,0,0,0,0,0,0,0,0;
0,0,0,1,1,1,0,0,0,0,0,0;
0,0,0,0,0,0,1,1,1,0,0,0;
0,0,0,0,0,0,0,0,0,1,1,1;
-1,0,0,-1,0,0,-1,0,0,-1,0,0;
0,-1,0,0,-1,0,0,-1,0,0,-1,0;
0,0,-1,0,0,-1,0,0,-1,0,0,-1]
b=[200-1.645*10;
300-1.645*10;
400-1.645*10;
200-1.645*10;
-100-1.645*10;
-300-1.645*10;
-400-1.645*10]
x0=[0,0,0,0,0,0,0,0,0,0,0,0];
lb=[0,0,0,0,0,0,0,0,0,0,0,0];
ub=[];
[X,FVAL]=fmincon(@myobj,x0,A,b,[],[],lb,ub)
运行显示:
Warning: Large-scale (trust region) method does not currently solve this type of problem,
switching to medium-scale (line search).
> In fmincon at 260
??? Error using ==> fmincon
FMINCON cannot continue because user supplied objective function failed with the following error:
Subscript indices must either be real positive integers or logicals.
请热心人士帮忙看下怎么改?谢谢!
fval不可能是0.我觉得求出来的x是1*12矩阵,需转换为4*3矩阵,代到目标函数中算才有结果,但我不知道怎么转换。
展开
化学工程
2007-07-25 · TA获得超过8900个赞
知道大有可为答主
回答量:2212
采纳率:80%
帮助的人:3337万
展开全部
程序编的非常好,只有一句:size(x) = [4,3]改为x =zeros(4,3) 即可。
%=================================
function fff
clear;clc;
A= [1,1,1,0,0,0,0,0,0,0,0,0;
0,0,0,1,1,1,0,0,0,0,0,0;
0,0,0,0,0,0,1,1,1,0,0,0;
0,0,0,0,0,0,0,0,0,1,1,1;
-1,0,0,-1,0,0,-1,0,0,-1,0,0;
0,-1,0,0,-1,0,0,-1,0,0,-1,0;
0,0,-1,0,0,-1,0,0,-1,0,0,-1]
b=[200-1.645*10;
300-1.645*10;
400-1.645*10;
200-1.645*10;
-100-1.645*10;
-300-1.645*10;
-400-1.645*10]
x0=[0,0,0,0,0,0,0,0,0,0,0,0];
lb=[0,0,0,0,0,0,0,0,0,0,0,0];
ub=[];
[X,FVAL,EXITFLAG]=fmincon(@myobj,x0,A,b,[],[],lb,ub)

function f=myobj(x)
c = [12 21 21; 13 20 23; 15 17 27; 17 19 31];
x =zeros(4,3)
y = c.*x;
y = sum(y(:));
s = 0;
for i = 1:4
sg = sum(x(i,:));
s = s+sg.^0.6;
end
f = y+200*s;
%=============================

运行结果:
X =

19.5167 69.5167 94.5167 38.7083 88.7083 113.7083 38.7083 88.7083 113.7083 19.5167 69.5167 94.5167

FVAL =

0

EXITFLAG =

1
光点科技
2023-08-15 广告
通常情况下,我们会按照结构模型把系统产生的数据分为三种类型:结构化数据、半结构化数据和非结构化数据。结构化数据,即行数据,是存储在数据库里,可以用二维表结构来逻辑表达实现的数据。最常见的就是数字数据和文本数据,它们可以某种标准格式存在于文件... 点击进入详情页
本回答由光点科技提供
hehedl521
2013-01-25
知道答主
回答量:11
采纳率:0%
帮助的人:11.7万
展开全部
Global optimal solution found.
Objective value: 112550.5
Objective bound: 112550.4
Infeasibilities: 0.000000
Extended solver steps: 83
Total solver iterations: 4753
Variable Value Reduced Cost
X1 50.65000 0.000000
X2 0.000000 7.000000
X3 132.9000 0.000000
X4 0.000000 3.438348
X5 0.000000 8.438348
X6 283.5500 0.000000
X7 65.80000 0.000000
X8 316.4500 0.000000
X9 0.000000 0.1050611E+09
X10 0.000000 2.000000
X11 0.000000 2.000000
X12 0.000000 0.1050611E+09
Row Slack or Surplus Dual Price
1 112550.5 -1.000000
2 0.000000 3.000000
3 0.000000 5.438348
4 1.300000 0.000000
5 183.5500 0.000000
6 0.000000 -215.0000
7 0.000000 -217.0000
8 0.000000 -40.97349
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式