Symmetric matrix is not symmetric
<p>I have recently written code for finite element method. Since my algorithm is generating a symmetric matrix, after gathering data for each element the resulting matrix should be symmetric.</p>

<p>However, after I run loop over element, the resulting global matrix is not symmetric.  The basic code structure is like this:</p>

<pre><code>A=zeros(dof,dof)

for (each element)
    loc_A = v'*(diagonal matrix)*v
         % (v is 1xN row vector)
         % loc_A is symmetric matrix

    A(K,K) = A(K,K)+loc_A
                 % (K is Nx1 column vector)
end
</code></pre>

<p>Since I add symmetric matrices, the resulting matrix should also be symmetric.</p>

<p>However, the resulting matrix is not symmetric (I checked it with <code>issymmetric(A)</code>).  I think this is because of round-off error.  If I add A=(A+A')/2, resulting matrix is symmetric (of course...).  However I don't want to do such thing. Is there any other remedy which makes <code>A</code> symmetric naturally without any post-processing?</p>