 s = reshape(v,d,d); s = s+s'-diag(diag(s));
<span class="keyword">if</span> nargout &lt; 2
    [M, S] = policy.fcn(policy, m, s);
<span class="keyword">else</span>
    [M, S, C, dMdm, dSdm, dCdm, dMds, dSds] = policy.fcn(policy, m, s);
    dd = length(M); dSds = reshape(dSds,dd,dd,d,d); df = zeros(dd,dd,d*(d+1)/2);
    <span class="keyword">for</span> i=1:dd; <span class="keyword">for</span> j=1:dd
        dSdsi(:,:) = dSds(i,j,:,:); dSdsi = dSdsi+dSdsi'-diag(diag(dSdsi));
        df(i,j,:) = dSdsi(tril(on