This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

SLEPc Eigenfunctions Have Unexpected Signs

0 votes

Hi,

The eigenfunctions for a particle in a 1D infinite well are the usual sin functions of the form

$U_1 = \sin(\pi x)$
$U_2 = \sin(2 \pi x)$
$U_3 = \sin(3 \pi x)$
etc.

However, when I solve this problem numerically FEniCS will sometimes produce eigenfunctions with the wrong sign

The code below, for example, produces the eigenfunctions

$U_1 = -\sin(\pi x)$
$U_2 = \sin(2 \pi x)$

even though it reports positive eigenvalues. Is there a way to insist on eigenfunctions that produce positive eigenvalues?

from dolfin import *

#define mesh and function space
mesh = IntervalMesh(200,-5,5)
V = FunctionSpace(mesh, 'Lagrange', 1)

#build essential boundary conditions
def u0_boundary(x, on_boundary):
return on_boundary

bc = DirichletBC(V,Constant(0.0) , u0_boundary)

#define functions
u = TrialFunction(V)
v = TestFunction(V)


#define problem
a = (inner(grad(u), grad(v)) \
     + Constant('0.0')*u*v)*dx
m = u*v*dx

A = PETScMatrix()
M = PETScMatrix()
_ = PETScVector()
L = Constant(0.)*v*dx

assemble_system(a, L, bc, A_tensor=A, b_tensor=_)
assemble_system(m, L, A_tensor=M, b_tensor=_)

#create eigensolver
eigensolver = SLEPcEigenSolver(A,M)
eigensolver.parameters['spectrum'] = 'smallest magnitude'
eigensolver.parameters['tolerance'] = 1.e-15

#solve for eigenvalues
neig = 2
eigensolver.solve(neig)

u = Function(V)
for i in range(neig):
    #extract next eigenpair
    r, c, rx, cx = eigensolver.get_eigenpair(i)
    print 'eigenvalue:', r

    #assign eigenvector to function
    u.vector()[:] = rx

    plot(u,interactive=True)

Is there a way to insist only one form is calculated?

asked Apr 14, 2014 by sixtysymbols FEniCS User (2,280 points)
edited Apr 14, 2014 by sixtysymbols

1 Answer

+1 vote
 
Best answer

Hi, the eigenvectors are not unique; if $ U $ is an eigenvector, then so is $ V=-U $. Therefore
I don't think you can claim that the sign is wrong. Does it matter for your application, where I assume, you are after some probability density functions? Btw, the eigenvectors produced by slepc are normalized to have $ ||U||_{l^2} =1 $, see here.

answered Apr 14, 2014 by MiroK FEniCS Expert (80,920 points)
selected Apr 14, 2014 by sixtysymbols

Hi,

Thanks for the reply. [edit]- I now understand that there is eigenvalue degeneracy. I've removed my previous misunderstanding from the comment.

I am unfortunately calculating some strange quantities like $\psi_m (\partial \psi_n/ \partial x)$ so I need to keep track of the signs.

Is there some property of $ \psi_n $ that you could check and identify whether you have
$ \psi_n $ or $ -\psi_n $ ? I think it boils down to properties of Hermite polynomials (for the even ones maybe sign at zero could work?)

I am doing some tests now and it might not even be necessary to keep track of the sign even for the stranger quantities I'm calculating. I will ultimately be introducing a general potential so it might be difficult to know a priori what the functions look like but hopefully this won't be a problem..

...