对称矩阵不对称

编程入门 行业动态 更新时间:2024-10-12 05:45:01
本文介绍了对称矩阵不对称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我最近编写了用于有限元方法的代码.由于我的算法生成的是对称矩阵,因此在为每个元素收集数据之后,所得矩阵应该是对称的.

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.

但是,所得矩阵不是对称的(我用issymmetric(A)对其进行了检查).我认为这是由于舍入错误.如果我加上A =(A + A')/2,则得到的矩阵是对称的(当然...).但是我不想做这样的事情.还有其他补救方法可以使A自然地对称而不进行任何后处理吗?

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?

推荐答案

这是由于舍入错误(除非您的代码中存在明显的错误). A = (A+A')/2通常可以解决此问题(这不是一项昂贵的操作),或者您可以告诉求解器您的全局矩阵是对称的(某些求解器(例如MUMPS)具有这种选择).

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.)

更多推荐

对称矩阵不对称

本文发布于:2023-10-26 17:29:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1530838.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:矩阵   对称   不对称

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!