登录论坛

查看完整版本 : [MATLAB混合编程] 求助:Matlab 6.5 'constr' 参数如何调用?


heartbridge
2009-06-30, 21:38
Optimization toolbox 中的 constr 函数, 我查帮助如下:
X=CONSTR('FUN',X,OPTIONS,VLB,VUB,'GRADFUN',P1,P2,...)
我的函数无导数表达式,所以没有GRADFUN,我正确编写 fun, 输入
X=CONSTR('FUN',X,OPTIONS,VLB,VUB,P1,P2,...)报错。 举例如下:
fun.m:
function [f,g]=fun(x,a)

f=a.*x(1);

g(1)=-x(1);


输入
a=1;
x0=[1];
opt(1)=1;
x=constr('fun(x,a0)',x0,opt,a):confused::confused:
结果:
> In C:\MATLAB6p5\toolbox\optim\constr.m at line 55
??? Error using ==> constr
Objective/constraint expression not properly defined.

heartbridge
2009-07-01, 00:53
大家帮帮忙阿,多谢了!