    Qi = sparse(A_row(idx:idxend)+1, A_col(idx:idxend)+1, A_val(idx:idxend),<span class="keyword">...</span>
0203       dim, dim, A_nnz(midx));
0204     <span class="comment">% symmetrize, was just upper triangle</span>
0205     Qi = Qi + triu(Qi,1)';
0206     <span class="comment">% swap sign, we want Ak &gt;= 0 (pos. def.) and it was neg. def.</span>
0207     Ak.Q{midx} = -Qi;
0208 
0209     idx = idxend+1;
0210   <span class="keyword">end</span>
0211 
0212   <span class="comment">% copy bilinear terms</s