その1
p=2の場合
clear; close all; p = 2; f1 = @(x) x.^2; f2 = @(x) (x-2).^2; w1s = 0:0.1:1; w2s = 0:0.1:1; x = -10:0.1:10; xopts = []; for idx=1:length(w1s) w1 = w1s(idx); for jdx=1:length(w2s) w2 = w2s(jdx); F = ((w1*f1(x)).^p+(w2*f2(x)).^2).^(1/p); if length(find(F==min(F)))>3 continue end xopt = x(find(F==min(F),1)); xopts(end+1) = xopt; end end xopts = unique(sort(xopts)); f1opts = f1(xopts); f2opts = f2(xopts); plot(f1opts,f2opts,'o'); hold on; x1 = 0:0.1:4; y1 = interp1(f2opts,f1opts,x1); plot(x1,y1,'-'); big;
その2
clear; close all; p = 2; a = 1/sqrt(2); f1 = @(x) 1-exp(-(x(:,1)-a).^2-(x(:,2)-a).^2); f2 = @(x) 1-exp(-(x(:,1)+a).^2-(x(:,2)+a).^2); w1s = 0:0.1:1; w2s = 0:0.1:1; x1 = -4:0.1:4; x2 = -4:0.1:4; x = [x1;x2]'; x1opts = []; x2opts = []; for idx=1:length(w1s) w1 = w1s(idx); for jdx=1:length(w2s) w2 = w2s(jdx); F = ((w1*f1(x)).^p+(w2*f2(x)).^2).^(1/p); if length(find(F==min(F)))>3 continue end xopt = x(find(F==min(F),1),:); x1opts(end+1) = xopt(1); x2opts(end+1) = xopt(2); end end xopts = [x1opts;x2opts]'; xopts = unique(sort(xopts),'rows'); f1opts = f1(xopts); f2opts = f2(xopts); plot(f1opts,f2opts,'o'); hold on; x1 = 0:0.1:1; y1 = interp1(f2opts,f1opts,x1,'spline'); plot(x1,y1,'-'); big;