%add_ex2
x = linspace(0,6,100);
for i=1:length(x)
    if (x(i)<=2)
        y(i) = 0.5*x(i).^2;
    elseif ((x(i) > 2) & (x(i) <= 4))
        y(i) = 2;
    elseif (x(i) > 4)
        y(i) = 6-x(i);
    end
end
plot(x,y)
