[讨论] 请问多变量方程式求最小值之根fmincon

楼主: hunghan13 (施肥)   2015-03-18 14:00:06
新手发问请各位大大海涵
先讲问题与限制
x0=zeros(6,2) 起始猜值,当作6组(x,y)座标
6组座标输出结果必须是 1<=x<=63 2<=y<=27,讲简单一点就是需要正数
有设定lb与ub
我的问题是输出y会出现负值,合理怀疑x也是有机会出现负数
因为fminsearch无法限制,改使用fmincon
顺便问问有没有其他方式
应该是不需要用到限制式与option
apcoor2=参考座标=2*1281的阵列,(x,y)限制与上述相同
disgu=6个座标之间的参考距离=距离会重复计算,所以是[6*6]的阵列
这部分改成不重复计算应该是不会影响结果,因为目前只是输出放大成两倍而已
output=可以先当作常数=[1*6]的阵列,
我需要计算[(x,y)与其他参考坐标之距离-参考距离].^2总和*output的最小解之根
以这样的方式去逼近6个不同的实际座标
%在x1,x2前面使用abs无法解决问题
%这东西有点像是mds
%目标函式
function y=objective4(x,apcoor2,disgu,output)
tmp=0;
for i=1:6
for k=1:6
for j=1:1281
tmp1=(sqrt((x(k,1)-apcoor2(j,1)).^2+(x(k,2)-apcoor2(j,2)).^2)
-disgu(k,i)).^2;
tmp=(tmp+tmp1);
end
end
tmp=tmp*(output(i)+0.01);%output可能会出现0
end
y=tmp;
%主程式呼叫
lb=[1 2];
ub=[63 21];
aptmp=data(:,1:2) %[2*1281]的阵列
[x,min]=fmincon(@(x) ....
objective4(x,aptmp,disg,output),x0,[],[],[],[],lb,ub);
  %这边100%写错,但是找不到我想要的资讯,需要输入的参数太多了
  %如果是fminsearch 会出现负数
%fminsearch(@objective4,x0,[],aptmp,disg,output);
coorg(:,1:2)=x;%放根
coorg(:,3)=min;%放解
重要的warning,简单讲看起来是不能用
Trust-region-reflective algorithm does not solve this type of problem, using
active-set algorithm. You could also try
the interior-point or sqp algorithms: set the Algorithm option to
'interior-point' or 'sqp' and rerun. For more help, see
Choosing the Algorithm in the documentation.
先感谢各位大大

Links booklink

Contact Us: admin [ a t ] ucptt.com