ivide,input,exp(2*X(1:D,i)'));
  R = s+diag(exp(2*X(1:D,i)));
  L = diag(exp(-X(1:D,i)));
  B = L*s*L+eye(D); iR = L/B*L;
  t = inp*iR;
  l = exp(-sum(t.*inp,2)/2); lb = l.*beta(:,i);
  tliK = t'*bsxfun(@times,l,iK(:,:,i));
  liK = K2\l;
  tlb = bsxfun(@times,t,lb);

  c = exp(2*X(D+1,i))/sqrt(det(R))*exp(sum(X(1:D,i)));
  detdX = diag(bsxfun(@times,det(R)*iR',2.*exp(2.*X(1:D,i))));    <span class="comment">% d(det R)/dX</span>
  cdX = -0.5*c/det(R).*detdX'+ c.*ones(1,D);       <span class="comment">% deriv