MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   MATLAB论坛 (https://www.labfans.com/bbs/forumdisplay.php?f=6)
-   -   [MATLAB基础] 求助 (https://www.labfans.com/bbs/showthread.php?t=13439)

yl122721400 2011-05-19 09:57

求助
 
利用文件编辑器为目标函数编写M文件(exefun.m)
function f=exefun(x)
f=671.175*(x(1)^2-x(2)^2)
5.2.2 编写约束条件M文件(execonfun.m)
function[c,ceq]=execonfun(x)
c(1)=1.2*10^5*(x(1)^2+x(2)^2)^0.5/4532355-2;
c(2)=1.2-1.2*10^5*(x(1)^2+x(2)^2)^0.5/4532355;
c(3)=8885.55*x(1)/(x(1)^4-x(2)^4)-300;
c(4)=3-x(1)+x(2);
ceq=[];
5.2.3 在MATLAB工具箱里调用程序fmincon求极值
x0=[55,50]
lb=[53;50]
ub=[59;56]
[x,fval,exitflag,output]=fmincon(@exefun,x0,[],[],[],[],lb,ub,@execonfun)
这个程序运行的时候出现下面错误
??? Error using ==> fmincon
FMINCON cannot continue because user supplied nonlinear constraint function
failed with the following error:

Error using ==> feval
Undefined function 'execonfun
请高手指教

anbcjys 2011-05-20 10:20

回复: 求助
 
[QUOTE=yl122721400;44460]利用文件编辑器为目标函数编写M文件(exefun.m)
function f=exefun(x)
f=671.175*(x(1)^2-x(2)^2)
5.2.2 编写约束条件M文件(execonfun.m)
function[c,ceq]=execonfun(x)
c(1)=1.2*10^5*(x(1)^2+x(2)^2)^0.5/4532355-2;
c(2)=1.2-1.2*10^5*(x(1)^2+x(2)^2)^0.5/4532355;
c(3)=8885.55*x(1)/(x(1)^4-x(2)^4)-300;
c(4)=3-x(1)+x(2);
ceq=[];
5.2.3 在MATLAB工具箱里调用程序fmincon求极值
x0=[55,50]
lb=[53;50]
ub=[59;56]
[x,fval,exitflag,output]=fmincon(@exefun,x0,[],[],[],[],lb,ub,@execonfun)
这个程序运行的时候出现下面错误
??? Error using ==> fmincon
FMINCON cannot continue because user supplied nonlinear constraint function
failed with the following error:

Error using ==> feval
Undefined function 'execonfun
请高手指教[/QUOTE]

function [c,ceq]=execonfun(x)


所有时间均为北京时间。现在的时间是 05:06

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.