用matlab求解一个优化问题(目标函数非线性,约束函数线性)
来源:学生作业帮 编辑:大师作文网作业帮 分类:英语作业 时间:2024/11/11 22:20:07
用matlab求解一个优化问题(目标函数非线性,约束函数线性)
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)=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矩阵,代到目标函数中算才有结果,但我不知道怎么转换。
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)=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矩阵,代到目标函数中算才有结果,但我不知道怎么转换。
程序编的非常好,只有一句:size(x) = [4,3]改为x =zeros(4,3) 即可.
%
运行结果:
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
%
运行结果:
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
用matlab求解一个优化问题(目标函数非线性,约束函数线性)
如何用Matlab求有限制条件的目标函数的最小值求解一个优化问题(目标函数非线性,约束函数线性)?
非线性约束优化 目标函数和约束函数 在matlab中出错
非线性函数Matlab求解
lingo非线性优化问题,目标函数有点复杂
有关MATLAB用solve函数求解非线性方程组的问题
matlab中约束条件非线性,求目标函数(线性)最大值怎么做?
关于lingo 求解目标函数为非线性规划的问题
急询:利用MATLAB求多目标线性函数优化问题?
利用MATLAB求多目标线性函数优化问题,
matlab约束优化问题
MATLAB求解非线性方程组用fsolve函数求解