iR(d,:)/2 -iR(:,d)*V(:,i)'/2;
    kdX(:,i,d) = bsxfun(@times,v(:,d),v(:,d));
  <span class="keyword">end</span> <span class="comment">% d</span>

  dVdt(:,i,:,i) = c*tliK;
  kdX(:,i,D+1) = 2*ones(1,n);                       <span class="comment">% pre-computation for later</span>

<span class="keyword">end</span> <span class="comment">% i</span>
dMdm = V';                                                <span class="comment">% derivatives w.r.t m</span>
dVdm = 2*permute(dMds,[2 1 3]);


<span class="comment"