[討論] 請問多變數方程式求最小值之根fmincon

看板MATLAB作者 (施肥)時間10年前 (2015/03/18 14:00), 10年前編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
新手發問請各位大大海涵 先講問題與限制 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. 先感謝各位大大 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.138.176.198 ※ 文章網址: https://www.ptt.cc/bbs/MATLAB/M.1426658408.A.618.html ※ 編輯: hunghan13 (140.138.176.198), 03/18/2015 14:02:36 ※ 編輯: hunghan13 (140.138.176.198), 03/18/2015 14:03:32 ※ 編輯: hunghan13 (140.138.176.198), 03/18/2015 14:04:00
文章代碼(AID): #1L2HHeOO (MATLAB)
文章代碼(AID): #1L2HHeOO (MATLAB)