# Missing the first eigenVector/eigenvalue

**URL:** <https://community.freefem.org/t/missing-the-first-eigenvector-eigenvalue/1167>\
**Category:** General Discussion\
**Created:** [August 20, 2021, 9:06am UTC](https://community.freefem.org/t/missing-the-first-eigenvector-eigenvalue/1167 "2021-08-20T09:06:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![NearAmvil](https://avatars.discourse-cdn.com/v4/letter/n/bb73d2/32.png) [@NearAmvil](https://community.freefem.org/u/NearAmvil)\
**Post date:** [August 20, 2021, 9:06am UTC](https://community.freefem.org/t/missing-the-first-eigenvector-eigenvalue/1167/1 "2021-08-20T09:06:16Z")

</div>

Hello !  
I’m currectly using FreeFEM++ to compute electronic structures.  
I wrote a FreeFREM++ code supposed to compute the lowest eigenvalues and eigenfunctions of the Schrödinger equation in 2D, that is to solve the elliptic eigenvalue problem

- \frac 12 \Delta u(x) + V(x) u(x) = E u(x) on a square with periodic boundary, where V is a given function.

The eigenvalues (E\_n) are ranked in nondecreasing order : E\_1 \le E\_2 \le E\_3 …

Following the example of acoustics I found in [Acoustics](https://doc.freefem.org/tutorials/acoustics.html) , I used the following code lines to solve the resulting generalized eigenvalue problem:

matrix K= rigidite(Vh,Vh,solver=Crout,factorize=1);  
matrix M= masse(Vh,Vh,solver=CG,eps=1e-20);

// Computation of the 5 lowest eigenvalues

int nev=5;  
real[int] ev(nev);  
Vh[int] eV1 (nev);  
real sigma= 0.0;  
real scale=10;  
int k=EigenValue(K,M,sym=true, sigma=sigma, value=ev,vector=eV1,tol=1e-10,maxit=0,ncv=0);

cout \<\< "First eigenvalue : " \<\< ev[0] \<\< endl;  
cout \<\< "Second eigenvalue : " \<\< ev[1] \<\< endl;  
cout \<\< "Third eigenvalue : " \<\< ev[2]\<\< endl;  
cout \<\< "Fourth eigenvalue : " \<\< ev[3] \<\< endl;  
cout \<\< "Fifth eigenvalue : " \<\< ev[4] \<\< endl;

Surprisingly, it seems that the code misses the lowest eigenvalue (ev[0] \simeq E\_2).

Does someone know how to fix this problem?

Thank you in advance!

Grégoire

---

<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:** [August 20, 2021, 9:20am UTC](https://community.freefem.org/t/missing-the-first-eigenvector-eigenvalue/1167/2 "2021-08-20T09:20:08Z")

</div>

I’d recommend that you use SLEPc instead of ARPACK, see, e.g., [FreeFem-sources/schrodinger-square-well-1d-SLEPc.edp at develop · FreeFem/FreeFem-sources · GitHub](https://github.com/FreeFem/FreeFem-sources/blob/develop/examples/hpddm/schrodinger-square-well-1d-SLEPc.edp) or [FreeFem-sources/schrodinger-harmonic-oscillator-2d-SLEPc.edp at develop · FreeFem/FreeFem-sources · GitHub](https://github.com/FreeFem/FreeFem-sources/blob/develop/examples/hpddm/schrodinger-harmonic-oscillator-2d-SLEPc.edp). It’s much easier to debug things there.

---

<div class="post-metadata">

**Author:** ![NearAmvil](https://avatars.discourse-cdn.com/v4/letter/n/bb73d2/32.png) [@NearAmvil](https://community.freefem.org/u/NearAmvil)\
**Post date:** [September 9, 2021, 12:33pm UTC](https://community.freefem.org/t/missing-the-first-eigenvector-eigenvalue/1167/3 "2021-09-09T12:33:24Z")

</div>

Hello prj and thank you for your answer !

I tried to use your example but couldn’t make it work because of an unsuccessful installation of PETSc & SLEPc on my virtual machine.  
So I tried to make it work on the cluster of my workplace, where FreeFEM++ is compiled without SLEPc/PETSc in /3rdparty folder. (I need to sudo make install some files, but don’t have rights to sudo.  
I tried to load my own installation of SLEPc/PETSc : the library seems to be loaded but I can’t call a single function of it.  
Example given :  
load " “/home/…/SLEPc.so” "  
load " “/home/…/PETSc.so” "

If I try to call for example the function EPSSolve, I’m told that the identifier EPSSolve doesn’t exist.  
Maybe isn’t it possible to load a library this way ?

Thank you in advance !

Grégoire

---

<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:** [September 9, 2021, 2:36pm UTC](https://community.freefem.org/t/missing-the-first-eigenvector-eigenvalue/1167/4 "2021-09-09T14:36:01Z")

</div>

You don’t need to use `sudo` if you build FreeFEM with a prefix. You must do that when on a cluster. Please configure and install FreeFEM correctly, see, e.g., [README.md](https://github.com/FreeFem/FreeFem-sources/blob/master/README.md#freefem), and then try again.

---

<div class="post-metadata">

**Author:** ![NearAmvil](https://avatars.discourse-cdn.com/v4/letter/n/bb73d2/32.png) [@NearAmvil](https://community.freefem.org/u/NearAmvil)\
**Post date:** [September 9, 2021, 3:08pm UTC](https://community.freefem.org/t/missing-the-first-eigenvector-eigenvalue/1167/5 "2021-09-09T15:08:00Z")

</div>

Hello prj !  
Thanks a lot for your answer. I followed the [README.ME](http://README.ME) instructions and it seems to work.

Thank you again and have a good afternoon.

Grégoire
