最優化計算入門
6個例子學習如何建造公式
EXAMPLE1:MANIFACTURING
如何把一個現實應用問題用數學公式表達出來
EXAMPLE2:TOYS
如何把一個繁瑣複雜的數據表格重新規劃
項目 | Train | Soldiers | Max |
---|---|---|---|
g(1) | 2 | 1 | 100 |
g(2) | 1 | 1 | 80 |
g(3) | 0 | 1 | 40 |
profit | 3 | 2 | ? |
EXAMPLE3:BEAMS
遇到諸如性能和成本這種矛盾變量時,如何衡量
EXAMPLE4:ANTENNAS
同時滿足多個用戶的要求,把多目標函數轉化成一個目標函數。
EXAMPLE5:RR ROBOT
用等高線分析,不同出發點可能會逼近不同的結果,我們很難尋找到全局極值點。
EXAMPLE6:RESOURCES ALLOCATION
如何把數學問題用符號來表達,尤其是涉及類似棋盤位置的問題。
Matlab代碼基礎格式
%%start
x = -2:.2:2;
y=x;
[x1,x2]=meshgrid(x,y);
Z = 200*norm([x1-5,x2-10])+150*norm([x1-10,x2-5])+200*norm([x1,x2-12])+300*norm([x1-12,x2]);
surf(x1,x2,Z);
contourf(x1,x2,Z);
% [c,h] = contourf(x1,x2,Z);clabel(c,h);colorbar;
% ... ... (X,Y,Z,[20,40,80,100,'k--']) select the value of line on the figure
x0=[0,0];
lb = [];% lower band
ub = [];% upper band
options =optimset('Display','iter','tolx',1.e-6,'MaxIter',40,'MaxFunEvals',200);
x = fminunc(@myfunc,x0,[],[],[],[],lb,ub,@myconstr,options);
%%
function f = myfunc (x)
% Find the best location of the new antennes Provity for the best Customers
% start from one point to find a best one
% 對於objective function的選擇是值得討論的。
% 1)min f(x) = dist(N,4)
% 2) min f(x) = dist(N,1)+dist(N,3)
% 3) min f(x) = weight of hours * dist(N,i)
% Variable X = (x1,x2) coord of the anntennes location
f = 200*norm([x(1)-5,x(2)-10])+150*norm([x(1)-10,x(2)-5])+200*norm([x(1),x(2)-12])+300*norm([x(1)-12,x(2)]);
endfunction
%%
function [g,h] = myconstr (x)
g(1) = 10 - norm([x(1)-5,x(2)]);
g(2) = 10 - norm([x(1)+5,x(2)-10]);
h = [];
endfunction