function min
g_1=0;
g_2=12;
g_3=24;
step=0.1;

dist=100;

l_1=0;
l_2=0;
l_3=0;
l_4=0;
l_5=0;

function [y]=g(x_1,x_2,x_3,x_4,x_5)
y=sqrt([(x_1-2) 10]*[(x_1-2) 10]')+sqrt([(x_2-x_1) (x_2-24)]*[(x_2-x_1) (x_2-24)]')+sqrt([(x_3-x_2) (24-x_2)]*[(x_3-x_2) (24-x_2)]')+sqrt([-x_3 (x_4-12)]*[-x_3 (x_4-12)]')+sqrt([x_5 -x_4]*[x_5 -x_4]')+sqrt([(12-x_5) 4]*[(12-x_5) 4]');
end

for x_1=g_1:step:g_3
    for x_2=g_2:step:g_3
        for x_3=g_1:step:g_3
            for x_4=g_1:step:g_2
                for x_5=g_1:step:g_2
                    if g(x_1,x_2,x_3,x_4,x_5) < dist
                        dist=g(x_1,x_2,x_3,x_4,x_5);
                        l_1=x_1;
                        l_2=x_2;
                        l_3=x_3;
                        l_4=x_4;
                        l_5=x_5;
                    end
                    x_5=x_5+step;
                end
                x_4=x_4+step;
            end
            x_3=x_3+step;
        end
        x_2=x_2+step;
    end
    x_1=x_1+step;
end
end
