# Discrete matrices are not strictly symmetric

**URL:** https://community.freefem.org/t/discrete-matrices-are-not-strictly-symmetric/1411
**Category:** General Discussion
**Created:** [January 5, 2022, 3:57pm UTC](https://community.freefem.org/t/discrete-matrices-are-not-strictly-symmetric/1411 "2022-01-05T15:57:53Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![wby](https://avatars.discourse-cdn.com/v4/letter/w/439d5e/32.png) [@wby](https://community.freefem.org/u/wby)
#### Post date: [January 5, 2022, 3:57pm UTC](https://community.freefem.org/t/discrete-matrices-are-not-strictly-symmetric/1411/1 "2022-01-05T15:57:53Z")

</div>

Dear all,  
Hi! Recently, I found that discrete matrices are not strictly symmetric, but in theory it should be symmetric. How can I get the strictly symmetric one?

varf a([uu,vv],[w,s])=  
int2d(Th)(  
2_mu_(dx(uu)_dx(w)+dy(vv)dy(s)+ ((dx(vv)+dy(uu))(dx(s)+dy(w)))/2 )  
+ lambda_(dx(uu)+dy(vv))\*(dx(w)+dy(s))  
)

- on(1,uu=0,vv=0)  
;

varf b([uu,vv],[w,s])=  
int2d(Th)(uu_w + vv_s) ;

matrix A= a(Vh,Vh,solver=“SPARSESOLVER”);  
matrix B= b(Vh,Vh,solver=CG,eps=1e-20);

1、I tried to At=(A+A’)/2, but It doesn’t work.  
2、I tried to use MatScale, but It is useless.  
3、I tried this,  
matrix A= a(Vh,Vh,solver=“SPARSESOLVER”);  
matrix B= b(Vh,Vh,solver=CG,eps=1e-20);  
A = (A+(A’));  
Mat At=A;  
At \*= 0.5;  
B = (B+B’);  
Mat Bt=B;  
Bt \*= 0.5;

But, Caught signal number 11 SEGV: Segmentation Violation, probably memory access out of range

Are there other methods???

Best regards,  
Baishi.

---

<div class="post-metadata">

### Author: ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)
#### Post date: [January 6, 2022, 6:02am UTC](https://community.freefem.org/t/discrete-matrices-are-not-strictly-symmetric/1411/2 "2022-01-06T06:02:53Z")

</div>

What do you mean by “not strictly symmetric”?

---

<div class="post-metadata">

### Author: ![wby](https://avatars.discourse-cdn.com/v4/letter/w/439d5e/32.png) [@wby](https://community.freefem.org/u/wby)
#### Post date: [January 6, 2022, 6:08am UTC](https://community.freefem.org/t/discrete-matrices-are-not-strictly-symmetric/1411/3 "2022-01-06T06:08:12Z")

</div>

Hi, prj, thanks for your reply!

I export the discrete matrices to MATLAB, and Not Strictly Symmetric means that

```
          >> max(max(A-A.'))
          ans =
               1.136868377216160e-13
          
          or norm(A-A')!=0
```

---

<div class="post-metadata">

### Author: ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)
#### Post date: [January 6, 2022, 6:14am UTC](https://community.freefem.org/t/discrete-matrices-are-not-strictly-symmetric/1411/4 "2022-01-06T06:14:21Z")

</div>

It’s nearly symmetric up to machine epsilon. You are likely loosing precision while exporting the matrix to MATLAB.

---

<div class="post-metadata">

### Author: ![wby](https://avatars.discourse-cdn.com/v4/letter/w/439d5e/32.png) [@wby](https://community.freefem.org/u/wby)
#### Post date: [January 6, 2022, 6:27am UTC](https://community.freefem.org/t/discrete-matrices-are-not-strictly-symmetric/1411/5 "2022-01-06T06:27:05Z")

</div>

Sorry, I am not sure that.  
I export them to SLEPc as binary file, however, can’t use many eps, such as lobpcg.

```
   [0]PETSC ERROR: The solver 'lobpcg' cannot be used for non-symmetric problems

```

So I want to know how to process manually makes it symmetric in FreeFem?

---

<div class="post-metadata">

### Author: ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)
#### Post date: [January 6, 2022, 6:36am UTC](https://community.freefem.org/t/discrete-matrices-are-not-strictly-symmetric/1411/6 "2022-01-06T06:36:42Z")

</div>

You should not use LOBPCG, much less robust than Krylov–Schur, but you need to add the option `-eps_gen_hermitian`.

---

<div class="post-metadata">

### Author: ![wby](https://avatars.discourse-cdn.com/v4/letter/w/439d5e/32.png) [@wby](https://community.freefem.org/u/wby)
#### Post date: [January 6, 2022, 7:28am UTC](https://community.freefem.org/t/discrete-matrices-are-not-strictly-symmetric/1411/7 "2022-01-06T07:28:28Z")

</div>

Thanks for your reminding, and I still want to know how to process manually makes it symmetric in FreeFem?

---

<div class="post-metadata">

### Author: ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)
#### Post date: [January 6, 2022, 7:30am UTC](https://community.freefem.org/t/discrete-matrices-are-not-strictly-symmetric/1411/8 "2022-01-06T07:30:19Z")

</div>

It is symmetric, up to machine epsilon.

---

<div class="post-metadata">

### Author: ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)
#### Post date: [January 6, 2022, 7:40am UTC](https://community.freefem.org/t/discrete-matrices-are-not-strictly-symmetric/1411/10 "2022-01-06T07:40:58Z")

</div>

```auto
mesh Th = square(10, 10);
varf vPb(u, v) = int2d(Th)(dx(u)*dx(v) + dy(u)*dy(v));
fespace Vh(Th, P1);
matrix A = vPb(Vh, Vh);
matrix B = A+A';
B = 0.5 * B;

```

---

<div class="post-metadata">

### Author: ![wby](https://avatars.discourse-cdn.com/v4/letter/w/439d5e/32.png) [@wby](https://community.freefem.org/u/wby)
#### Post date: [January 6, 2022, 7:52am UTC](https://community.freefem.org/t/discrete-matrices-are-not-strictly-symmetric/1411/11 "2022-01-06T07:52:10Z")

</div>

That doesn’t work…  
[2d-beam-eigen.edp](https://community.freefem.org/uploads/short-url/fvD5rRBObDUzg5QBA56jwzr29S1.edp) (4.2 KB)  
Segmentation fault (core dumped)

```
    matrix AA= a(Vh,Vh,solver="SPARSESOLVER"); 
    matrix C = AA+AA';
    matrix A = 0.5 * C;
    matrix BB= b(Vh,Vh,solver=CG,eps=1e-20); 
    C = BB+BB';
    matrix B = 0.5 * C;
```

---

<div class="post-metadata">

### Author: ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)
#### Post date: [January 6, 2022, 7:55am UTC](https://community.freefem.org/t/discrete-matrices-are-not-strictly-symmetric/1411/12 "2022-01-06T07:55:51Z")

</div>

That does work… [2d-beam-eigen.edp](https://community.freefem.org/uploads/short-url/6Yov5ocK1XIABlOQ99PWOriidPI.edp) (2.7 KB)

---

<div class="post-metadata">

### Author: ![wby](https://avatars.discourse-cdn.com/v4/letter/w/439d5e/32.png) [@wby](https://community.freefem.org/u/wby)
#### Post date: [January 6, 2022, 8:16am UTC](https://community.freefem.org/t/discrete-matrices-are-not-strictly-symmetric/1411/13 "2022-01-06T08:16:37Z")

</div>

Thanks, but another problem occurs.  
Segmentation fault (core dumped) when call the subroutine Eigenvalue

I don’t know what happen 😓

I want to compare the results of Eigvalue(ARPACK) in FreeFem with ARPACK in SLEPc

---

<div class="post-metadata">

### Author: ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)
#### Post date: [January 6, 2022, 8:20am UTC](https://community.freefem.org/t/discrete-matrices-are-not-strictly-symmetric/1411/14 "2022-01-06T08:20:09Z")

</div>

I don’t recommend the use of ARPACK (here is a prime example of why), and I don’t know how to fix this.

---

<div class="post-metadata">

### Author: ![wby](https://avatars.discourse-cdn.com/v4/letter/w/439d5e/32.png) [@wby](https://community.freefem.org/u/wby)
#### Post date: [January 6, 2022, 8:23am UTC](https://community.freefem.org/t/discrete-matrices-are-not-strictly-symmetric/1411/15 "2022-01-06T08:23:59Z")

</div>

Well, thank you very much for your help today

---

<div class="post-metadata">

### Author: ![wby](https://avatars.discourse-cdn.com/v4/letter/w/439d5e/32.png) [@wby](https://community.freefem.org/u/wby)
#### Post date: [January 6, 2022, 4:06pm UTC](https://community.freefem.org/t/discrete-matrices-are-not-strictly-symmetric/1411/16 "2022-01-06T16:06:37Z")

</div>

Hi, prj, there still exist the problem that the binary file without processing was considered non-symmetric by SLEPc. Because of this, I can’t use many eps 😭

---

<div class="post-metadata">

### Author: ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)
#### Post date: [January 6, 2022, 4:19pm UTC](https://community.freefem.org/t/discrete-matrices-are-not-strictly-symmetric/1411/17 "2022-01-06T16:19:23Z")

</div>

Why are you not calling SLEPc through FreeFEM? In which case it won’t complain if you give the proper option I mentioned earlier.
