x=u_x(:,2)
%hist(x)
t = linspace (0,1,11)
xr=zeros(10,1)
for k=1:10
  sum=0
  for i=1:300
    if(x(i)>=t(k) & x(i)<t(k+1))
      sum=sum+1
    end
    xr(k)=sum/300
  end
end
tc=t(1:10)+0.05
%plot(tc,xr)
pb = xr
function fx = fX(argt,alpha)
  fx = argt^alpha*(1-argt)*(alpha+1)*(alpha+2)
end

function fx = fXHelp(alpha)
  t=[0.00000   0.10000   0.20000   0.30000   0.40000   0.50000
   0.60000   0.70000   0.80000   0.90000   1.00000]
  fx=fX(t,alpha)
end


function pk = pK(k,alpha, t)
  pk = 0.1*fXHelp(t(k),alpha)
end

function pk = pKHelp(alpha)
  k=[0.00000   0.10000   0.20000   0.30000   0.40000   0.50000
   0.60000   0.70000   0.80000   0.90000   1.00000]
  t=[0.00000   0.10000   0.20000   0.30000   0.40000   0.50000
   0.60000   0.70000   0.80000   0.90000   1.00000]
  pk=pK(k,alpha,t)
end

function g = G(alpha, argpb, argt)
  sum=0
  for k=1:10
    s=0
    s=argpb(k)-pKHelp(k,alpha, argt)
    s=s*s
    sum=sum+s
  end
  g=sum
end

function g = GHelp(alpha)
  pb=[0.0066667   0.0200000   0.0466667   0.1000000   0.1466667   0.1833333
   0.1700000  0.1600000  0.1300000  0.0366667]
   t=[0.00000   0.10000   0.20000   0.30000   0.40000   0.50000
   0.60000   0.70000   0.80000   0.90000   1.00000]
   g=G(alpha, pb, t)
 end

min = fminsearch(@(alpha) GHelp, [0])

