关于极值求解问题
请问在计算两变量极值问题时调用MATLAB中的什么函数来计算??我是个新手,请大侠把求解步骤给写下非常感谢!!:) 1# chenbinok一般来说用fminsearch就可以,具体如下(来自帮助文件): 2# qibbxxt
minF(x)=(x1-2)^2+(x2-1)^2
约束条件为:g1(x)=x1-2*x2+1=0
g2(x)=-x1^2/4-x2^2+1>o
搜索初始点为(2,2)
我是个新手 谢谢大侠能帮我写下这个程序非常感谢!!! 带约束条件的我还不晓得怎么去写程序谢谢你的帮助 本帖最后由 qibbxxt 于 2010-9-19 16:45 编辑
3# chenbinok
目标函数
function y=mufun_ex0919(x)
y=(x(1)-2).^2+(x(2)-1).^2;
约束条件
function =mycon_ex0919(x)
c=x(1).^2/4+x(2).^2-1;
ceq=x(1)-2*x(2)+1;
运行
x = fmincon(@mufun_ex0919,,[],[],[],[],[],[],@mycon_ex0919,[])
Warning: Trust-region-reflective method does not currently solve this type of problem,
using active-set (line search) instead.
> In fmincon at 439
Local minimum found that satisfies the constraints.
Optimization completed because the objective function is non-decreasing in
feasible directions, to within the default value of the function tolerance,
and constraints were satisfied to within the default value of the constraint tolerance.
<stopping criteria details>
Active inequalities (to within options.TolCon = 1e-006):
lower upper ineqlin ineqnonlin
1
x =
0.8229 0.9114
>> options=optimset('Algorithm','active-set');x = fmincon(@mufun_ex0919,,[],[],[],[],[],[],@mycon_ex0919,options)
Local minimum found that satisfies the constraints.
Optimization completed because the objective function is non-decreasing in
feasible directions, to within the default value of the function tolerance,
and constraints were satisfied to within the default value of the constraint tolerance.
<stopping criteria details>
Active inequalities (to within options.TolCon = 1e-006):
lower upper ineqlin ineqnonlin
1
x =
0.8229 0.9114
还可以参考参考这个:http://forum.simwe.com/viewthread.php?tid=879437 试下1stOpt:
MinFunction (x1-2)^2+(x2-1)^2;
x1-2*x2+1=0;
-x1^2/4-x2^2+1>=0;
结果:
目标函数值(最小): 0.31250000000005
x1: 1.49999999999993
x2: 1.24999999999997
约束函数:
1: x1-2*x2+1-(0) = 0
2: -x1^2/4-x2^2+1-(0) = 3.330669074E-14 5# qibbxxt
非常感谢你的指导 6# shamohu
感觉你算的不对,x1和x2不满足约束条件啊,此问题可以把等式约束条件代入另外两个算式中,化成二次函数求极值,x2的最大值为为(sqrt(7)+1)/4 仔细琢磨了下,发现如下问题:
对表达式计算如:-2^2
Matlab, MM, Maple结果为:-4
Excel, 1stOpt结果为:4
如果表达式为:0-2^2,则结果均为-4
估计是当表达式第一个字符为“-”号时,如“-2^2”,Excel,1stOpt将其自动视为“(-2)^2”。
修正后代码:
MinFunction (x1-2)^2+(x2-1)^2;
x1-2*x2+1=0;
0-x1^2/4-x2^2+1>=0;
结果:
目标函数值(最小): 1.3934649806893
x1: 0.822875655532295
x2: 0.911437827766148
约束函数:
1: x1-2*x2+1-(0) = 0
2: 0-x1^2/4-x2^2+1-(0) = 0 9# shamohu
恩,看来不同程序的优先级不同,这是我用lingo解得
min=(x1-2)^2+(x2-1)^2;
x1^2/4+x2^2-1<0;
x1-2*x2+1=0;
Local optimal solution found.
Objective value: 1.393465
Infeasibilities: 0.1303735E-10
Extended solver steps: 5
Total solver iterations: 30
Variable Value Reduced Cost
X1 0.8228757 0.000000
X2 0.9114378 0.000000
Row Slack or Surplus Dual Price
1 1.393465 -1.000000
2 0.000000 1.846591
3 0.000000 1.594491
从严格数学角度讲,这个最小值是没有的,只有下确界,当x2=(sqrt(7)+1)/4的时候 Lingo好像和1stOpt一样都会把“-2^2”当做“(-2)^2”处理。
min=(x1-2)^2+(x2-1)^2;
-x1^2/4-x2^2+1>=0;
x1-2*x2+1=0;
结果:
Global optimal solution found.
Objective value: 0.3125000
Objective bound: 0.3125000
Infeasibilities: 0.000000
Extended solver steps: 2
Total solver iterations: 235
Model Class: NLP
Total variables: 2
Nonlinear variables: 2
Integer variables: 0
Total constraints: 3
Nonlinear constraints: 2
Total nonzeros: 6
Nonlinear nonzeros: 4
Variable Value Reduced Cost
X1 1.500000 0.000000
X2 1.250000 0.000000
Row Slack or Surplus Dual Price
1 0.3125000 -1.000000
2 0.000000 -1.499998
3 0.000000 2.124998
恩,Forcal中编译 “-2^2” 会出错,Forcal强制要求用户写成 “(-2)^2” 或者“-(2^2)”。 8# qibbxxt
你好,请问功能函数包含的参数里既有“随机变量”又存在“区间变量”,这该如何去写计算程序 期待你的回答 写这个计算程序就是为了求解一个部件的可靠性指标或可靠度 利用函数linprog即可求解,函数的具体意义可以参照matlab帮助文档,里面讲解非常详细。
页:
[1]