clear
xmin=0; 
xmax=20;
n=2;
nk(1)=2;
Jmin(1)=fungsi(xmin);
xstar(1)=xmin;
k(1)=1;
for i=2:100
   nk(i)=n;
   dx=(xmax-xmin)/n;
   clc
   k(i)=i;
   Jmin(i)=fungsi(xmin);
   xstar(i)=xmin;
   for j=1:n 
    J1=fungsi(xmin+(j-1)*dx);
    J2=fungsi(xmin+(j*dx));
    if J2<J1
       Jmin(i)=J2;
       xstar(i)=xmin+(j*dx);
    end
 end
 if abs(Jmin(i)-Jmin(i-1))<0.00000000000001
    n=n+1;
 elseif abs(Jmin(i)-Jmin(i-1))<0.000001
    break
 else
    n=2*n;
 end
end       
plot(xstar,Jmin), grid on, xlabel('xstar'), ylabel('Jmin')
pause
plot(xstar), grid on, xlabel('step k'), ylabel('xstar') 
pause
plot(Jmin), grid on, xlabel('step k'), ylabel('Jmin')
format short
Hasilk=k'
format long
Hasilx=xstar' 
HasilJ=Jmin'

