声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1146|回复: 1

[编程技巧] 怎么用matlab求解一个优化问题(目标函数非线性,约束函数线性)

[复制链接]
发表于 2007-7-25 10:58 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

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.
请热心人士帮忙看下怎么改?谢谢!

[ 本帖最后由 eight 于 2007-7-25 13:10 编辑 ]
回复
分享到:

使用道具 举报

发表于 2007-7-25 12:23 | 显示全部楼层
加上:
options = optimset('LargeScale','off');
[X,FVAL]=fmincon(@myobj,x0,A,b,[],[],lb,ub,options) ;
再试试

[ 本帖最后由 花如月 于 2007-7-25 12:25 编辑 ]
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-12-12 07:49 , Processed in 0.055882 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表