找回密码
 注册
Simdroid-非首页
查看: 180|回复: 14

关于极值求解问题

[复制链接]
发表于 2010-9-18 15:43:06 | 显示全部楼层 |阅读模式 来自 湖南长沙
请问在计算两变量极值问题时调用MATLAB中的什么函数来计算??我是个新手,请大侠把求解步骤给写下  非常感谢!!:)
发表于 2010-9-18 21:14:07 | 显示全部楼层 来自 河北廊坊
Simdroid开发平台
1# chenbinok
一般来说用
  1. fminsearch
复制代码
就可以,具体如下(来自帮助文件):

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×

评分

1

查看全部评分

回复 不支持

使用道具 举报

 楼主| 发表于 2010-9-19 15:48:16 | 显示全部楼层 来自 湖南长沙
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)


我是个新手 谢谢大侠能帮我写下这个程序  非常感谢!!!
回复 不支持

使用道具 举报

 楼主| 发表于 2010-9-19 15:49:59 | 显示全部楼层 来自 湖南长沙
带约束条件的我还不晓得怎么去写程序  谢谢你的帮助
回复 不支持

使用道具 举报

发表于 2010-9-19 16:43:27 | 显示全部楼层 来自 河北廊坊
本帖最后由 qibbxxt 于 2010-9-19 16:45 编辑

3# chenbinok
目标函数

  1. function y=mufun_ex0919(x)
  2. y=(x(1)-2).^2+(x(2)-1).^2;
复制代码
约束条件

  1. function [c,ceq]=mycon_ex0919(x)
  2. c=x(1).^2/4+x(2).^2-1;
  3. ceq=x(1)-2*x(2)+1;
复制代码
运行

  1. x = fmincon(@mufun_ex0919,[2,2],[],[],[],[],[],[],@mycon_ex0919,[])
  2. Warning: Trust-region-reflective method does not currently solve this type of problem,
  3. using active-set (line search) instead.
  4. > In fmincon at 439
  5. Local minimum found that satisfies the constraints.
  6. Optimization completed because the objective function is non-decreasing in
  7. feasible directions, to within the default value of the function tolerance,
  8. and constraints were satisfied to within the default value of the constraint tolerance.
  9. <stopping criteria details>
  10. Active inequalities (to within options.TolCon = 1e-006):
  11.   lower      upper     ineqlin   ineqnonlin
  12.                                      1
  13. x =
  14.     0.8229    0.9114
  15. >> options=optimset('Algorithm','active-set');x = fmincon(@mufun_ex0919,[2,2],[],[],[],[],[],[],@mycon_ex0919,options)
  16. Local minimum found that satisfies the constraints.
  17. Optimization completed because the objective function is non-decreasing in
  18. feasible directions, to within the default value of the function tolerance,
  19. and constraints were satisfied to within the default value of the constraint tolerance.
  20. <stopping criteria details>
  21. Active inequalities (to within options.TolCon = 1e-006):
  22.   lower      upper     ineqlin   ineqnonlin
  23.                                      1
  24. x =
  25.     0.8229    0.9114
复制代码

还可以参考参考这个:http://forum.simwe.com/viewthread.php?tid=879437

评分

1

查看全部评分

回复 不支持

使用道具 举报

发表于 2010-9-19 18:07:48 | 显示全部楼层 来自 北京海淀
试下1stOpt:

  1. MinFunction (x1-2)^2+(x2-1)^2;
  2.             x1-2*x2+1=0;
  3.             -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

评分

1

查看全部评分

回复 不支持

使用道具 举报

 楼主| 发表于 2010-9-19 19:57:24 | 显示全部楼层 来自 湖南长沙
5# qibbxxt

非常感谢你的指导
回复 不支持

使用道具 举报

发表于 2010-9-20 08:41:30 | 显示全部楼层 来自 河北廊坊
6# shamohu
感觉你算的不对,x1和x2不满足约束条件啊,此问题可以把等式约束条件代入另外两个算式中,化成二次函数求极值,x2的最大值为为(sqrt(7)+1)/4
回复 不支持

使用道具 举报

发表于 2010-9-20 09:39:41 | 显示全部楼层 来自 北京海淀
仔细琢磨了下,发现如下问题:
对表达式计算如:-2^2
Matlab, MM, Maple结果为:-4
Excel, 1stOpt结果为:4

如果表达式为:0-2^2,则结果均为-4

估计是当表达式第一个字符为“-”号时,如“-2^2”,Excel,1stOpt将其自动视为“(-2)^2”。

修正后代码:

  1. MinFunction (x1-2)^2+(x2-1)^2;
  2.             x1-2*x2+1=0;
  3.             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

评分

1

查看全部评分

回复 不支持

使用道具 举报

发表于 2010-9-20 10:42:07 | 显示全部楼层 来自 河北廊坊
9# shamohu
恩,看来不同程序的优先级不同,这是我用lingo解得

  1. min=(x1-2)^2+(x2-1)^2;
  2. x1^2/4+x2^2-1<0;
  3. x1-2*x2+1=0;
复制代码

  1.   Local optimal solution found.
  2.   Objective value:                              1.393465
  3.   Infeasibilities:                             0.1303735E-10
  4.   Extended solver steps:                               5
  5.   Total solver iterations:                            30

  6.                        Variable           Value        Reduced Cost
  7.                              X1       0.8228757            0.000000
  8.                              X2       0.9114378            0.000000
  9.                             Row    Slack or Surplus      Dual Price
  10.                               1        1.393465           -1.000000
  11.                               2        0.000000            1.846591
  12.                               3        0.000000            1.594491
复制代码

从严格数学角度讲,这个最小值是没有的,只有下确界,当x2=(sqrt(7)+1)/4的时候

评分

1

查看全部评分

回复 不支持

使用道具 举报

发表于 2010-9-20 14:00:23 | 显示全部楼层 来自 北京海淀
Lingo好像和1stOpt一样都会把“-2^2”当做“(-2)^2”处理。

  1. min=(x1-2)^2+(x2-1)^2;
  2. -x1^2/4-x2^2+1>=0;
  3. x1-2*x2+1=0;
复制代码
结果:

  1. Global optimal solution found.
  2.   Objective value:                             0.3125000
  3.   Objective bound:                             0.3125000
  4.   Infeasibilities:                              0.000000
  5.   Extended solver steps:                               2
  6.   Total solver iterations:                           235

  7.   Model Class:                                       NLP

  8.   Total variables:                      2
  9.   Nonlinear variables:                  2
  10.   Integer variables:                    0

  11.   Total constraints:                    3
  12.   Nonlinear constraints:                2

  13.   Total nonzeros:                       6
  14.   Nonlinear nonzeros:                   4

  15.                                 Variable           Value        Reduced Cost
  16.                                       X1        1.500000            0.000000
  17.                                       X2        1.250000            0.000000

  18.                                      Row    Slack or Surplus      Dual Price
  19.                                        1       0.3125000           -1.000000
  20.                                        2        0.000000           -1.499998
  21.                                        3        0.000000            2.124998
复制代码
回复 不支持

使用道具 举报

发表于 2010-9-21 21:12:33 | 显示全部楼层 来自 山东淄博
恩,Forcal中编译 “-2^2” 会出错,Forcal强制要求用户写成 “(-2)^2” 或者“-(2^2)”。
回复 不支持

使用道具 举报

 楼主| 发表于 2010-9-25 10:37:19 | 显示全部楼层 来自 湖南长沙
8# qibbxxt

你好,请问功能函数包含的参数里既有“随机变量”又存在“区间变量”,这该如何去写计算程序   期待你的回答
回复 不支持

使用道具 举报

 楼主| 发表于 2010-9-25 10:39:15 | 显示全部楼层 来自 湖南长沙
写这个计算程序就是为了求解一个部件的可靠性指标或可靠度
回复 不支持

使用道具 举报

发表于 2010-10-11 19:35:56 | 显示全部楼层 来自 河北秦皇岛
利用函数linprog即可求解,函数的具体意义可以参照matlab帮助文档,里面讲解非常详细。
回复 不支持

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Simapps系列直播

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-10-4 23:32 , Processed in 0.072248 second(s), 21 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表