<>先是两个编好的函数:</P>
<>function f=fun(x)<BR>f=-2*x(1)-x(2);</P>
<>function[g,ceq]=mycon2(x)<BR>g=[x(1)^2+x(2)^2-25;x(1)^2-x(2)^2-7]</P>
<P>然后运行这个脚本文件:</P>
<P>x0=[3;2.5];<BR>vlb=[0 0];<BR>vub=[5 10];<BR>[x,fval,exitflag,output]=fmincon('fun',x0,[],[],[],[],vlb,vub,'mycon2');</P>
<P>可是显示以下错误:</P>
<P>g =</P>
<P> -9.7500<BR> -4.2500</P>
<P>??? Error using ==> fmincon<BR>FMINCON cannot continue because user supplied nonlinear constraint function<BR> failed with the following error:</P>
<P>One or more output arguments not assigned during call to 'feval'.</P>
<P>Error in ==> C:\MATLAB6p1\work\Untitled6.m<BR>On line 4 ==> [x,fval,exitflag,output]=fmincon('fun',x0,[],[],[],[],vlb,vub,'mycon2');</P> |