icted mean
  
  iK2beta = K2\beta(:,i);
  dMds(i,:,:) = c*t'*tlb/2-iR*M(i)/2;
  dMdX(i,D+2,i) = -c*sum(l.*(2*exp(2*X(D+2,i))*iK2beta));           % OK
  dMdX(i,D+1,i) = -dMdX(i,(i-1)*(D+2)+D+2);
  
  dVdX(:,i,D+2,i) = -((l.*(2*exp(2*X(D+2,i))*iK2beta))'*t*c)';
  dVdX(:,i,D+1,i) = -dVdX(:,i,D+2,i);
  
  dsi = -bsxfun(@times,inp2,2.*inp2);                 % d(sum(inp2.*inp2,2))/dX
  dslb = zeros(1,D);
  
  for d = 1:D
    sqdi = K(:,:,i).*bsxfun(@minus,ii(:,d),ii(:,d)');
    sqdiBi = sqdi*beta(:,i);
    tlbdi