j</span>

      <span class="keyword">if</span> i==j
        daQi = ii*QdXi + bsxfun(@times,-2*ii(:,d),Q2(d,:)); <span class="comment">% d(ii*Q)/dXi</span>
        dsaQi = sum(daQi.*ii,2) - 2.*aQ(:,d).*ii(:,d); dsaQj = dsaQi;
        dsbQi = dsaQi; dsbQj = dsbQi;
        dm2i = -2*daQi*ii' + 2*(bsxfun(@times,aQ(:,d),ii(:,d)')<span class="keyword">...</span>
          +bsxfun(@times,ii(:,d),aQ(:,d)')); dm2j = dm2i; <span class="comment">% -2*aQ*ij'/di</span>
      <span class="keyword">else</span>
        db