clear all

figure(1)
  figure(2)
  
  
%  figure(3)
 a=pi/10;  b=a*4; rmin=1e4;  xmin=[0 0 0 0 0];  xeve=[0 0 0 0 0];  % the angle values of the pentagon
 
 for l=1:3
     figure(l)
 for i=1:5
     
%  plot([0,cos(a+b*(i-1))],[0,sin(a+b*(i-1))],'k');
%  hold on
 plot([cos(a+b*(i-1)),cos(a+b*(i))],[sin(a+b*(i-1)),sin(a+b*(i))],'k');  % plot the pentagon
 hold on
 
 end
 
 end
 
 
 
 for i=1:1000
 
 m1=rand;
 m2=rand;
 m3=rand;
 m4=rand;
 m5=rand;  % rand numbers
 
 
 lo=[1e3,0.7,1,0.01,0];
 hi=[1e6,1,4,10,1];

 m=[1e3+(1e6-1e3)*m1,0.7+0.3*m2,1+3*m3,0.1+9.9*m4,m5];   % the random initial value
 %m=[40088.4886448656,0.733593606078156, 3.59999997497713 , 5.34011925908481, 0.939999817447977 ];


options= optimset('Algorithm','active-set','TolFun',1e-6,'MaxFunEvals',1e4,'MaxIter',1e4)
[x,fval,exitflag,output,lambda,grad]=fmincon(@f_con_high,m,[],[],[],[],[1e3,0.7,1,0.1,0],[1e6,1,4,10,1],[],options)

 if fval<34  % determine what is the real minimum
    
    if fval<rmin
        rmin=fval;  % find the smallest "minimum"
        
        xmin=x;
        
    end
    
    figure(1)
    if exitflag==1 || exitflag==4 || exitflag==5
   plot(m1*cos(a),m1*sin(a),'g');plot(m2*cos(a+b),m2*sin(a+b),'g');plot(m3*cos(a+b*2),m3*sin(a+b*2),'g');plot(m4*cos(a+b*3),m4*sin(a+b*3),'g');plot(m5*cos(a+b*4),m5*sin(a+b*4),'g');
  % plot the initial points that yield global minimum
   plot((x(1)-lo(1))/(hi(1)-lo(1))*cos(a),(x(1)-lo(1))/(hi(1)-lo(1))*sin(a),'+b');   % plot the global minimum argument
   plot((x(2)-lo(2))/(hi(2)-lo(2))*cos(a+b),(x(2)-lo(2))/(hi(2)-lo(2))*sin(a+b),'+b');
    plot((x(3)-lo(3))/(hi(3)-lo(3))*cos(a+b*2),(x(3)-lo(3))/(hi(3)-lo(3))*sin(a+b*2),'+b');
    plot((x(4)-lo(4))/(hi(4)-lo(4))*cos(a+b*3),(x(4)-lo(4))/(hi(4)-lo(4))*sin(a+b*3),'+b');
    plot((x(5)-lo(5))/(hi(5)-lo(5))*cos(a+b*4),(x(5)-lo(5))/(hi(5)-lo(5))*sin(a+b*4),'+b');
    
    end
    
    
  % plot([m1*cos(a),m2*cos(a+b),m3*cos(a+b*2),m4*cos(a+b*3),m5*cos(a+b*4),m1*cos(a)],[m1*sin(a),m2*sin(a+b),m3*sin(a+b*2),m4*sin(a+b*3),m5*sin(a+b*4),m1*sin(a)],'g')
    hold on
    
    if m1<0.02 || m1>0.13
%         figure(3)
%         plot([m1*cos(a),m2*cos(a+b),m3*cos(a+b*2),m4*cos(a+b*3),m5*cos(a+b*4),m1*cos(a)],[m1*sin(a),m2*sin(a+b),m3*sin(a+b*2),m4*sin(a+b*3),m5*sin(a+b*4),m1*sin(a)],'b')
% 
%         hold on
        
    end
 else
    figure(2)
    
  %  axis([-1 2 -1 1])
  plot(m1*cos(a),m1*sin(a),'r');plot(m2*cos(a+b),m2*sin(a+b),'r');plot(m3*cos(a+b*2),m3*sin(a+b*2),'r');plot(m4*cos(a+b*3),m4*sin(a+b*3),'r');plot(m5*cos(a+b*4),m5*sin(a+b*4),'r');
  
    % plot the initial points that yield nonglobal minimum
  
             plot((x(1)-lo(1))/(hi(1)-lo(1))*cos(a),(x(1)-lo(1))/(hi(1)-lo(1))*sin(a),'+b'); % plot the non-global minimum argument
   plot((x(2)-lo(2))/(hi(2)-lo(2))*cos(a+b),(x(2)-lo(2))/(hi(2)-lo(2))*sin(a+b),'+b');
    plot((x(3)-lo(3))/(hi(3)-lo(3))*cos(a+b*2),(x(3)-lo(3))/(hi(3)-lo(3))*sin(a+b*2),'+b');
    plot((x(4)-lo(4))/(hi(4)-lo(4))*cos(a+b*3),(x(4)-lo(4))/(hi(4)-lo(4))*sin(a+b*3),'+b');
    plot((x(5)-lo(5))/(hi(5)-lo(5))*cos(a+b*4),(x(5)-lo(5))/(hi(5)-lo(5))*sin(a+b*4),'+b');
        


 % plot([m1*cos(a),m2*cos(a+b),m3*cos(a+b*2),m4*cos(a+b*3),m5*cos(a+b*4),m1*cos(a)],[m1*sin(a),m2*sin(a+b),m3*sin(a+b*2),m4*sin(a+b*3),m5*sin(a+b*4),m1*sin(a)],'r')
    hold on
end

 end
  figure(1)
              plot((xmin(1)-lo(1))/(hi(1)-lo(1))*cos(a),(xmin(1)-lo(1))/(hi(1)-lo(1))*sin(a),'+m');
   plot((xmin(2)-lo(2))/(hi(2)-lo(2))*cos(a+b),(xmin(2)-lo(2))/(hi(2)-lo(2))*sin(a+b),'+m');
    plot((xmin(3)-lo(3))/(hi(3)-lo(3))*cos(a+b*2),(xmin(3)-lo(3))/(hi(3)-lo(3))*sin(a+b*2),'+m');
    plot((xmin(4)-lo(4))/(hi(4)-lo(4))*cos(a+b*3),(xmin(4)-lo(4))/(hi(4)-lo(4))*sin(a+b*3),'+m');
    plot((xmin(5)-lo(5))/(hi(5)-lo(5))*cos(a+b*4),(xmin(5)-lo(5))/(hi(5)-lo(5))*sin(a+b*4),'+m');
 
 
 rmin       % the minimum value
 x             % th argument of the minimum
 
    
    
    
    