function site warning off; a = [ 1.25 8.75 0.50 5.75 3.00 7.25 ]'; b = [ 1.25 0.75 4.75 5.00 6.50 7.25 ]'; d = [ 3 5 4 7 6 11 ]'; xq = [ 5 2 ]'; yq = [ 1 7 ]'; t = [20 20 ]'; % fixed site at xq, yq A = kron(eye(2), ones(1,6)); B = t; Aeq = kron(ones(1,2), eye(6)); Beq = d; [x,fv] = fmincon(@tkm,ones(12,1),... A,B, Aeq,Beq,zeros(12,1),[ ],[ ],optimset,... a,b,xq,yq) subplot(1,2,1); sdrw(x,a,b,d,xq,yq,t); pause % choose sites both A2 = [A zeros(2,4)]; B2 = t; Aeq2 = [Aeq zeros(6,4)]; Beq2 = d; [x,fv2] = fmincon(@tkm1,ones(16,1),... A2,B2, Aeq2,Beq2,[zeros(12,1);-inf*ones(4,1)],[ ],... [ ],optimset,... a,b) subplot(1,2,2); sdrw(x(1:12),a,b,d,x([13 14]),x([15 16]),t); title(['save ' num2str(fv-fv2) ' ton*km']); function y = tkm(x,a,b,xq,yq) % x(1:6) A to all points % x(7:12) B to all points dist1 = sqrt( (xq(1)-a).^2 + (yq(1)-b).^2 ); dist2 = sqrt( (xq(2)-a).^2 + (yq(2)-b).^2 ); dist = [dist1; dist2]; y = dist' * x; function y = tkm1(x,a,b) % x(1:6) A to all points % x(7:12) B to all points % x(13:14) moving site's x coodinates % x(15:16) moving site's y coodinates xq = x([13 14]); yq = x([15 16]); xx = x(1:12); y = tkm(xx,a,b,xq,yq); function sdrw(x,a,b,d,xq,yq,t) hold on; for k = 1:6, plot(a(k),b(k),'bd','markersize',d(k)); end for k = 1:2, plot(xq(k),yq(k),'ro','markersize',t(k)); for s = 1:length(a), if x((k-1)*6+s)>0, plot([xq(k) a(s)],[yq(k) b(s)],'k:',... 'linewidth',x((k-1)*6+s)); end end end