Implicit Functions


Matlab code:

function implicit_funcs

fsize = 16;

f1 = @(x) x;
f2 = @(x) 1.5*x;

xAR = -2.5:.05:2.5;
for n=1:length(xAR)
    x = xAR(n);
    myfun = @(y) abs(y-f1(x)) + (y-f2(x))^2;
    y_star(n) = fminsearch(myfun,0);
end
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)|+ (y-f2(x))^2','FontSize',fsize)
xlabel('x','FontSize',fsize)
ylabel('y','FontSize',fsize)
set(gca,'FontSize',fsize)

clear
figure
fsize = 16;

I=3;
f{1} = @(x) x;
f{2} = @(x) 1.5*x+1;
f{3} = @(x) .5*x+1;
function o=myfun2(y)
    o = 0;
    for i=1:I
        o = o + abs(y-f{i}(x));
    end
end
xAR = -5:.1:5;
for n=1:length(xAR)
    x = xAR(n);
    y_star(n) = fminsearch(@myfun2,0);
end
plot(xAR,f{1}(xAR),'k-',xAR,f{2}(xAR),'k-',xAR,f{3}(xAR),'k-',xAR,y_star,'r.','LineWidth',2)
legend('f1','f2','f3','y*')
title('y*(x) = arg min_y = \Sigma_i |y-f_i(x)|','FontSize',fsize)
xlabel('x','FontSize',fsize)
ylabel('y','FontSize',fsize)
set(gca,'FontSize',fsize)

clear
figure
fsize = 16;

I=3;
f{1} = @(x) x;
f{2} = @(x) 1.5*x+1;
f{3} = @(x) .5*x+1;
function o=myfun3(y)
    o = 0;
    for i=1:I
        o = o + (y-f{i}(x))^2;
    end
end
xAR = -5:.1:5;
for n=1:length(xAR)
    x = xAR(n);
    y_star(n) = fminsearch(@myfun3,0);
end
plot(xAR,f{1}(xAR),'k-',xAR,f{2}(xAR),'k-',xAR,f{3}(xAR),'k-',xAR,y_star,'r.','LineWidth',2)
legend('f1','f2','f3','y*')
title('y*(x) = arg min_y = \Sigma_i (y-f_i(x))^2','FontSize',fsize)
xlabel('x','FontSize',fsize)
ylabel('y','FontSize',fsize)
set(gca,'FontSize',fsize)

end
This entry was posted in Uncategorized and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s