Symmetric matrix is not symmetric

和自甴很熟 提交于 2019-12-10 23:32:40

问题


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.

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

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

Since I add symmetric matrices, the resulting matrix should also be symmetric.

However, the resulting matrix is not symmetric (I checked it with issymmetric(A)). 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 A symmetric naturally without any post-processing?


回答1:


This is due to round-off error (unless you have an obvious bug in your code). This issue is normally solved by A = (A+A')/2 (this is not an expensive operation) or you can tell the solver that your global matrix is symmetric (some solvers (i.e. MUMPS) have such an option.)



来源:https://stackoverflow.com/questions/37648152/symmetric-matrix-is-not-symmetric

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!