(This time, including derivatives.) Closed form solutions are possible for some of these, I know.

…which of course has a constant derivative.

Matlab code:

function implicit_funcs options = optimset('TolX',1e-15,'MaxFunEvals',1e5,'MaxIter',1e5); fsize = 16; e = 1e-5; f1 = @(x) 5*x; f2 = @(x) x; xAR = -3:.05:3; for n=1:length(xAR) x = xAR(n); myfun = @(y) 5*abs(y-f1(x))^2 + abs(y-f2(x))^2; y_star(n) = fminsearch(myfun,0,options); % approximate derivative with one sided finite diff x = xAR(n)+e; myfun = @(y) 5*abs(y-f1(x))^2 + abs(y-f2(x))^2; y_star2(n) = fminsearch(myfun,y_star(n),options); end figure(1) plot(xAR,f1(xAR),'k-',xAR,f2(xAR),'k--',xAR,y_star,'r-','LineWidth',2) legend('f1','f2','y*') title('y*(x) = arg min_y = |y-f1(x)|^{2}+ (y-f2(x))^2','FontSize',fsize) xlabel('x','FontSize',fsize) ylabel('y','FontSize',fsize) set(gca,'FontSize',fsize) figure(2), plot(xAR,(y_star2-y_star)/e,'r-','LineWidth',2); title('y*(x) = arg min_y = |y-f1(x)|^{2}+ (y-f2(x))^2','FontSize',fsize) legend('dy*(x)/dx') set(gca,'FontSize',fsize) xlabel('x','FontSize',fsize) end

Advertisements