% Problem # 10 (Fichtenholz's Function # 1 or Himmelblau's Function # 2)
%
% For Fichtenholz's Function No.1 (Problem # 10):
% Range of initial points: 0 <= x <= 10 (see for Himmelblau)
% Global maxima: x=7.978665706811959
% f(x)=7.916727371587783
%
% For Himmelblau's Function No.2:
% Range of initial points: -7.85 <= x <= 7.85
% Two global minimum: x={-4.913180450455435,4.913180450455435}
% f(x)=-4.814469889712269
% Coded by: Ali R. Alroomi | Last Update: 14 Feb. 2015 | www.al-roomi.org
 
clear
clc
warning off
 
S=2; % to select between Fichtenholz and Himmelblau 
if S==1 % Fichtenholz
    xmin=0;
    xmax=10;
else % Himmelblau
    xmin=-7.85;
    xmax=7.85;
end
R=100000; % steps resolution
x=xmin:(xmax-xmin)/R:xmax;
 
for i=1:length(x)
    f(i)=x(i)*sin(x(i));
end
 
plot(x,f,'r','LineWidth',2);grid;set(gca,'FontSize',12);
xlabel('x','FontName','Times','FontSize',20,'FontAngle','italic');
ylabel('f(x)','FontName','Times','FontSize',20,'FontAngle','italic');