求助:用matlab解一个非线性规划问题

2025-05-21 14:21:31
推荐回答(1个)
回答1:

首先,你这个是求最小值吧,假如取最大值的话,只要x(1)取无限接近0,那么y就是正无穷了嘛。其次,1 \ x(1) 应该是1/x(1)吧。

下面是代码,至于初值x0是怎么得到的,我是通过遗传算法多次试验得到的,你就别问我了,这个初值够好的了。

fun=@(x)(1 / ( 4 * x(1) + 8 * x(2) +3 * x(3) + 9 * x(4) + 7 * x(5) ) + ...
           0.6 * ( 5 * x(1) + 3 * x(2) + 7 * x(3) + 6 * x(4) + 8 * x(5) ) + ...
            0.4 * ( 1/x(1) + 2 / x(2) + 3 / x(3) + 4 / x(4) +5 / x(5) ));
x0=[ 1.1   16.5    0.65    0.9    0.8];%初值
Aeq=[1,1,1,1,1];%等式约束的系数
beq=20;
lb=[0,0,0,0,0];%下界(lower Bounds)
options = optimset;
options = optimset(options,'Display', 'off');
options = optimset(options,'Algorithm', 'interior-point');
[x,fval] = ...
fmincon(fun,x0,[],[],Aeq,beq,lb,[],[],options);
fprintf('fun的最小值为%d\n',fval)
fprintf('x(1)~x(5)分别为:')
x


fun的最小值为4.912650e+01
x(1)~x(5)分别为:x =
    0.5766   16.9585    0.7067    0.9421    0.8161