matlab程序 怎么用非线性规划的方法求曲面方程的最大和最小值,求最大值的程序在下面

2025-04-19 12:20:25
推荐回答(1个)
回答1:

先保存自定义函数文件
yfun.m
function y=yfun(Z)
y=-14.4*Z(1)+93.5*Z(2)+10.8*Z(3)-1483.8*Z(4)-30.5*Z(1)*Z(2)...
-13.7*Z(1)*Z(3)+1762.9*Z(1)*Z(4)-256.2*Z(2)*Z(3)...
+1752.1*Z(2)*Z(4)+1711.4*Z(3)*Z(4);
y=-y;
end
然后,在命令框输入
>>A = [-1 0 0 0;1 0 0 0;0 -1 0 0;0 1 0 0;0 0 -1 0;0 0 1 0;0 0 0 -1;0 0 0 1;1 1 1 1; -1 -1 -1 -1;];
>>b==[-0.35; 0.6; -0.09; 0.15; -0.3; 0.5; -0.07; 0.09; 1; -1];
>>Z0= [0.4;0.1;0.42;0.08];
>>[zvalue yvalue] = fmincon(@yfun,Z0,A,b)
运行结果:
Optimization terminated: Magnitude of directional derivative in search
direction less than 2*options.TolFun and maximum constraint violation
is less than options.TolCon.
Active inequalities (to within options.TolCon = 1e-006):
lower upper ineqlin ineqnonlin
4
5
9
10
zvalue =
0.469134664040214
0.15
0.3
0.0808653359597858
yvalue =
-4.56721006934595