matlab程序 怎么用非线性规划的方法求曲面方程的最大和最小值,求最大值的程序在下面
程序运行不了,不知道有什么问题啊,详细点,希望能把你的程序贴出来,先谢了。曲面方程系数有上下界,要求在曲面方程最大时4个未知数的值。functionfangfunctio...
程序运行不了,不知道有什么问题啊,详细点,希望能把你的程序贴出来,先谢了。曲面方程系数有上下界,要求在曲面方程最大时4个未知数的值。
function fang
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)
end 展开
function fang
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)
end 展开
展开全部
先保存自定义函数文件
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
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询