# Solve Eigenvalue problem - Segmentation Fault

**URL:** <https://community.freefem.org/t/solve-eigenvalue-problem-segmentation-fault/2274>\
**Category:** General Discussion\
**Created:** [February 10, 2023, 8:16am UTC](https://community.freefem.org/t/solve-eigenvalue-problem-segmentation-fault/2274 "2023-02-10T08:16:51Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Loic](https://avatars.discourse-cdn.com/v4/letter/l/e9c0ed/32.png) [@Loic](https://community.freefem.org/u/Loic)\
**Post date:** [February 10, 2023, 8:16am UTC](https://community.freefem.org/t/solve-eigenvalue-problem-segmentation-fault/2274/1 "2023-02-10T08:16:51Z")

</div>

Hello all,

I am wondering how to solve such eigen value problem with FreeFEM (in which the matrices are not associated with a finite element operator).

 ![EigenValue_Problem](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/1/1feb2028a96741387297c182d964144456f563da.png)

In this case the first and second matrices are spare matrices and the Phi\_i are FE functions.

When I applied the classical method:  
`int l = EigenValue(OP, B, sym=true, sigma=sigma, value=ev, vector=eV, tol=1e-10, maxit=0, ncv=0)` I get a segmentation fault.

Thank you in advance for your help,

Best regards,

Loïc,

---

<div class="post-metadata">

**Author:** ![cmd](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/cmd/32/67_2.png) [@cmd](https://community.freefem.org/u/cmd)\
**Post date:** [February 10, 2023, 9:31am UTC](https://community.freefem.org/t/solve-eigenvalue-problem-segmentation-fault/2274/2 "2023-02-10T09:31:40Z")

</div>

It’s not quite clear what you need here, but let me try to help anyways.

First, I’m not sure if this is part of your questions, but you can create (or load) a sparse matrix without using FE functions.

Second, if the Psi are not FE functions, you may need to use `array=` instead of `vector=` when you call `EigenValue`.

Hope that helps!

---

<div class="post-metadata">

**Author:** ![Loic](https://avatars.discourse-cdn.com/v4/letter/l/e9c0ed/32.png) [@Loic](https://community.freefem.org/u/Loic)\
**Post date:** [February 10, 2023, 9:51am UTC](https://community.freefem.org/t/solve-eigenvalue-problem-segmentation-fault/2274/3 "2023-02-10T09:51:51Z")

</div>

Hello Chris,

Thank you for your reply,

Yes the Psi\_i are FE function. Basically they are some basis functions that I have computed on a fine mesh inside my coarse element.

And when I declared my eigenvalue as array, I get

> Impossible to cast in \<13FEbaseArrayKnIdE\>.

Best regards,

Loïc

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [February 10, 2023, 10:22am UTC](https://community.freefem.org/t/solve-eigenvalue-problem-segmentation-fault/2274/4 "2023-02-10T10:22:53Z")

</div>

Can you send your freefem script, because your problem is not clear for me!

---

<div class="post-metadata">

**Author:** ![Loic](https://avatars.discourse-cdn.com/v4/letter/l/e9c0ed/32.png) [@Loic](https://community.freefem.org/u/Loic)\
**Post date:** [February 10, 2023, 10:54am UTC](https://community.freefem.org/t/solve-eigenvalue-problem-segmentation-fault/2274/5 "2023-02-10T10:54:42Z")

</div>

[BASIS\_TEST.zip](https://community.freefem.org/uploads/short-url/bITchOXICzHzUazh8Ok1Qn1YP2R.zip) (803.7 KB)  
Dear Frédéric,

Thank you for your help, I have prepared a MWE of my problem.  
You can find it in attachment, here:  
[MWE\_EigenValue\_Problem.edp](https://community.freefem.org/uploads/short-url/5JlC3RBejKt6gGoUV5PX3D9echv.edp) (2.4 KB)

Best regards,

Loïc,

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [February 10, 2023, 3:12pm UTC](https://community.freefem.org/t/solve-eigenvalue-problem-segmentation-fault/2274/6 "2023-02-10T15:12:54Z")

</div>

The script corrected

1. your FEspace have 2 compote,
2. the number of converged EV is greater the nev.

[MWE\_EigenValue\_Problem.edp](https://community.freefem.org/uploads/short-url/t1SNcpmYrDaDgNRURR5wxf2RhBR.edp) (2.5 KB)

---

<div class="post-metadata">

**Author:** ![Loic](https://avatars.discourse-cdn.com/v4/letter/l/e9c0ed/32.png) [@Loic](https://community.freefem.org/u/Loic)\
**Post date:** [February 10, 2023, 3:40pm UTC](https://community.freefem.org/t/solve-eigenvalue-problem-segmentation-fault/2274/7 "2023-02-10T15:40:23Z")

</div>

Thanks for your help !

Best regards,

Loïc,

---

<div class="post-metadata">

**Author:** ![Loic](https://avatars.discourse-cdn.com/v4/letter/l/e9c0ed/32.png) [@Loic](https://community.freefem.org/u/Loic)\
**Post date:** [February 15, 2023, 1:57pm UTC](https://community.freefem.org/t/solve-eigenvalue-problem-segmentation-fault/2274/8 "2023-02-15T13:57:59Z")

</div>

Hello all,

With this correction  
[MWE\_EigenValue\_Problem\_Correct.edp](https://community.freefem.org/uploads/short-url/mWHldsJ63NN9NKG0mD43GPdJONV.edp) (2.5 KB)  
(with the same set of basis functions previously attached), for each element, the FreeFEM code is able to find 3 eigenvalues (whose values are 0 and 48 and 120).

However, when I do the calculation with python using the same matrices, we find 4 eigenvalues : the three found by FreeFEM (0 and 48 and 120) + another one (whose value is 240).

Why FreeFEM does not find this fourth eigenvalue ?

Thank you in advance for your help,

Best regards,

Loïc,

---

<div class="post-metadata">

**Author:** ![cmd](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/cmd/32/67_2.png) [@cmd](https://community.freefem.org/u/cmd)\
**Post date:** [February 15, 2023, 7:54pm UTC](https://community.freefem.org/t/solve-eigenvalue-problem-segmentation-fault/2274/9 "2023-02-15T19:54:52Z")

</div>

The `EigenValue` function uses ARPACK, which is not designed to compute the complete eigenspectrum of a matrix. It is generally used for computing only a few eigenvalues/eigenvectors from large sparse matrix systems.

If you change the shift to a value closer to 240, you should find that eigenvalue (though in this case you won’t see the zero eigenvalue.)

---

<div class="post-metadata">

**Author:** ![Loic](https://avatars.discourse-cdn.com/v4/letter/l/e9c0ed/32.png) [@Loic](https://community.freefem.org/u/Loic)\
**Post date:** [February 16, 2023, 6:58am UTC](https://community.freefem.org/t/solve-eigenvalue-problem-segmentation-fault/2274/10 "2023-02-16T06:58:45Z")

</div>

Hello,

Thank you for your reply,

However is there a way to compute more eigenvalues (if we do not know a priori the following eigenvalues) ?

Best regards,

Loïc,

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [February 19, 2023, 3:03pm UTC](https://community.freefem.org/t/solve-eigenvalue-problem-segmentation-fault/2274/11 "2023-02-19T15:03:13Z")

</div>

If the matrix is not to big (\<1000) you can use lapack!

---

<div class="post-metadata">

**Author:** ![Loic](https://avatars.discourse-cdn.com/v4/letter/l/e9c0ed/32.png) [@Loic](https://community.freefem.org/u/Loic)\
**Post date:** [February 20, 2023, 7:06am UTC](https://community.freefem.org/t/solve-eigenvalue-problem-segmentation-fault/2274/12 "2023-02-20T07:06:26Z")

</div>

Thanks !

But I cannot find the same values with the function `dggev` of lapack.

It works fine with the function` EPSSolve` of PETSc. However I wonder if it exists a parameter to compute the eigenvalue from the smallest to the largest ?

Best regards,

Loï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:** [February 20, 2023, 8:26am UTC](https://community.freefem.org/t/solve-eigenvalue-problem-segmentation-fault/2274/13 "2023-02-20T08:26:54Z")

</div>

> -eps\_type lapack

is the only choice if you need the full spectrum.
