% Discontinuous Function
% Range of initial points: 0 <= x <= 10
% Global minima: x=6
% f(x)=-1.159146731333981
% Coded by: Ali R. Alroomi | Last Update: 02 March 2015 | www.al-roomi.org
 
clear
clc
warning off
 
xmin=0;
xmax=10;
R=100000; % steps resolution
x=xmin:(xmax-xmin)/R:xmax;
 
for i=1:length(x)
    
    if x(i)<6
        x1(i)=x(i);
        f1(i)=(x(i)/3)*sin(x(i))*cos(x(i));
    else
        x2(i-length(x1))=x(i);
        f2(i-length(x1))=(x(i)/4)*sin(0.9*x(i));
    end
    
end
 
hold;grid;set(gca,'FontSize',12);
plot(x1,f1,'r','LineWidth',2);
plot(x1(end),f1(end),'.r', 'MarkerSize', 30);
plot(x2,f2,'r','LineWidth',2);
plot(x2(1),f2(1),'.r', 'MarkerSize', 30);
xlabel('x','FontName','Times','FontSize',20,'FontAngle','italic');
ylabel('f(x)','FontName','Times','FontSize',20,'FontAngle','italic');