返回信息流求指教这样调用fmincon函数错在哪里了
function f=fun(x)
load housing_train.txt;
A=housing_train;
[m,n]=size(A);
for i=1:m;
if A(i,n)>24;
A(i,n)=1;
else A(i,n)=-1;
end;
end;
X=A(:,1:n-1);
Y=A(:,n);
f=zeros(1,m);
for i=1:m;
for j=1:m;
f=f+Y(i)'*Y(j)'*x(1,i)*x(1,j)*exp(-norm(X(i)-X(j))^2/(2*1^2));
end;
end;
这是我的fun函数,其中A读到的是个433X14的矩阵
>> fmincon('fun',x,[],[],[],[],0,1)
Warning: To use the default trust-region-reflective algorithm you must supply the gradient in the objective function and set
the GradObj option to 'on'. FMINCON will use the active-set algorithm instead. For information on applicable algorithms, see
Choosing the Algorithm in the documentation.
> In fmincon at 492
Error using fmincon (line 674)
User supplied objective function must return a scalar value.
然后调用的时候就这样了~求指教啊,哪里出问题了
这是一条镜像帖。来源:北邮人论坛 / matlab / #9496同步于 2012/11/26
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Matlab机器人发帖
跪求教fmincon函数怎么用!
xprince
2012/11/26镜像同步1 回复
订阅后,新回复会通过你的通知中心匿名送达。
1 条回复
还是把原题直接贴出来吧,光看一段程序看不出什么问题。
【 在 xprince 的大作中提到: 】
: 求指教这样调用fmincon函数错在哪里了
: function f=fun(x)
: load housing_train.txt;
: ...................