声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1150|回复: 6

[编程技巧] 我用优化工具箱怎么老是得到的x是和vub一样啊??

[复制链接]
发表于 2007-7-17 14:57 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
麻烦大家看一下,我用优化工具箱怎么老是得到的x是和vub一样啊??

function  [f,g]=fun(x)
%x由[x1,x2,x3,x4,x5]
%x1是消声片的厚度,单位为m, x2是片间距(m), x3是片高(m), x4是有效片长(m), x5是片数
  IL=35;
  Q=18;
  c=343;
%   l=0.26=x4;
  f1=10;
%   h=0.095=x3;
  f2=7000;
  vel=8;
  alfa=0.072;
  bta=1;
  kec=alfa+bta*x(4);
  density=1.29;
  dH=kec*density*vel*vel/2;
  lmax=75;
  f=x(4)*(x(1)+x(2))*(x(2)+x(3))*(1+Q/c*x(2)*x(3)*x(5))/2*IL*x(2)*x(2)*x(3);
  g(1)=x(2)-756.8/f1;
  g(2)=10.32/f2-x(1);
  g(3)=Q/x(5)*x(2)*x(3)-sqrt(2*dH/kec*density);
  g(4)=x(4)-(kec-alfa)/bta;
  g(5)=60*log10(Q)-(lmax+13)-50*log10(x(5)*x(2)*x(3));
  g(6)=0.4-x(2)/(x(1)+x(2));
  g(7)=x(2)/(x(1)+x(2))-0.65;


运行程序:
clear,clc
x0=[0.09,0.172,2.040,1.940,24];
vlb=[0.09,0.172,2.040,1.940,24];
vub=[0.218,0.3,2.2,2.1,32];

x=constr('fun',x0,vlb,vub);

[ 本帖最后由 eight 于 2007-7-17 15:05 编辑 ]
回复
分享到:

使用道具 举报

发表于 2007-7-18 16:41 | 显示全部楼层
你好象用的很老的Matlab版本.
用新的fmincon吧,很容易处理,看看help文件就能解决.
也可以搜索论坛,已经讨论过多次这种问题了.
 楼主| 发表于 2007-7-18 20:41 | 显示全部楼层

麻烦大家看看,这个程序哪里错了??

function  f=confun2(x)
l=0.26;
B=0.436;
  f=x(1)*x(3)*l*B/(x(2)+x(3))

function  [g,c]=myfun2(x)
l=0.26;
B=0.436;
g(1)=15-1.25*2(x(1)+x(2))*l/(x(1)*x(2));
g(2)=18*x(2)*(3)/x(2)*x(3)*B-10;
g=[g(1);g(2)];
c=[];


clear,clc
x0=[0.0,0.0,2];
% A=[0 1 0];
% b=[0.63];
% lb=[0.09,0.172,2.04];
% ub=[0.218,0.3,2.2];
% options=optimset('LargeScale','off','Display','iter');
x=fmincon('confun2',x0,[],[],[],[],[],[],'myfun2');

怎么运行出来以后,老是出错啊!!实在是找不到是哪里错了,望各位指教一二,不胜感激!!
错误是:
Warning: Large-scale (trust region) method does not currently solve this type of problem,
switching to medium-scale (line search).
> In fmincon at 274
  In runfun2 at 9
??? Error using ==> fmincon
FMINCON cannot continue because user supplied nonlinear constraint function
failed with the following error:
Error: File: D:\Program Files\MATLAB71\work\ad\myfun2.m Line: 5 Column: 15
Unbalanced or misused parentheses or brackets.

Error in ==> runfun2 at 9
x=fmincon('confun2',x0,[],[],[],[],[],[],'myfun2');
发表于 2007-7-18 20:53 | 显示全部楼层
1。confun2,myfun2写成两个m文件
2。每个文件结尾加“end”
 楼主| 发表于 2007-7-18 21:06 | 显示全部楼层

不好意思,我还是有点不太明白您的意思!!

不好意思,我还是有点不太明白您的意思!!您的意思是这样的吗::
function  f=confun2(x)
l=0.26;
B=0.436;
  f=x(1)*x(3)*l*B/(x(2)+x(3))
end

function  [g,c]=myfun2(x)
l=0.26;
B=0.436;
g(1)=15-1.25*2(x(1)+x(2))*l/(x(1)*x(2));
g(2)=18*x(2)*(3)/x(2)*x(3)*B-10;
g=[g(1);g(2)];
c=[];
end


clear,clc
x0=[0.0,0.0,2];
% A=[0 1 0];
% b=[0.63];
% lb=[0.09,0.172,2.04];
% ub=[0.218,0.3,2.2];
% options=optimset('LargeScale','off','Display','iter');
x=fmincon('confun2',x0,[],[],[],[],[],[],'myfun2');
 楼主| 发表于 2007-7-18 21:18 | 显示全部楼层

您好!!

g(1)=15-1.25*2(x(1)+x(2))*l/(x(1)*x(2));
少了一个乘号,
可是改完了之后,

clear,clc
x0=[0.09,0.005,0.010];
A=[0 1 0];
b=[0.63];
lb=[0.09,0.005,0.010];
ub=[0.1,0.020,0.1];
options=optimset('LargeScale','off','Display','iter');
x=fmincon('confun2',x0,A,b,[],[],lb,ub,'myfun2',options);
又出现如下的错误:
                               max                   Directional   First-order
Iter F-count        f(x)   constraint    Step-size   derivative   optimality Procedure
    0      4    0.0068016            0                                         
    1      8   0.00517865            0            1     -0.00124        0.144   
    2     12   0.00517864            0            1   -1.17e-008        0.263  Hessian modified twice  
Optimization terminated: magnitude of search direction less than 2*options.TolX
and maximum constraint violation is less than options.TolCon.
Active inequalities (to within options.TolCon = 1e-006):
  lower      upper     ineqlin   ineqnonlin
    1                                 
    3   
请问:现在的这个要怎么改正呢??
如何才能Active inequalities (to within options.TolCon = 1e-006):
谢谢了
发表于 2007-7-19 08:52 | 显示全部楼层
这次语法正确,但是叠代可能不收敛,或者根本无解。
自己定性判断一下方程,特别是将方程进一步简化看看感觉如何
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-10-3 00:21 , Processed in 0.065125 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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