clear; close all; x = -10:0.1:10; f1 = x.^2; f2 = (x-2).^2; plot(f1,f2,'rx'); hold on; xlim([-0.2 0.2]); w1s = 0:0.1:1.0; w2s = 0:0.1:1.0; xopts = []; for i=1:length(w1s) w1 = w1s(i); for j=1:length(w2s) w2 = w2s(j); C = w1*f1+w2*f2; xopt = x(find(C==min(C),1)); xopts(end+1)=xopt; end end xopts = xopts(2:end); xopts = unique(sort(xopts)) f1opts = xopts.^2; f2opts = (xopts-2).^2; plot(f1opts,f2opts,'bo'); xlim([0,5]); ylim([0,5]); figure(); plot(f1,f2,'rx'); hold on; plot(f1opts,f2opts,'bo'); xlim([0,20]); ylim([0,20]); big;