回 帖 发 新 帖 刷新版面

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

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

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');

回复列表 (共2个回复)

沙发


[quote]
g(1)=15-1.25*2(x(1)+x(2))*l/(x(1)*x(2));
[/quote]
少了一个"*"
g(1)=15-1.25*2*(x(1)+x(2))*l/(x(1)*x(2));

板凳

g(1)=15-1.25*2(x(1)+x(2))*l/(x(1)*x(2));

这一行里面那个2后面好像少了个"*"

而且x(1)和x(2)都是0,会提示"divided by zero"

我来回复

您尚未登录,请登录后再回复。点此登录或注册