# How to ensure the same global sign convention in row vectors of a matrix (due to many separate eigensolver calls)

Sorry for the title, I struggled to describe my problem concisely.

I have a function \phi(p,Z) which is evaluated on a grid pgrid, Zgrid and available as a matrix phi. My goal is to calculate the second derivative (later also first one) with respect to the parameter p. For that I employed a simple finite difference method, but I encountered some unusually large derivatives. I traced it back to the following problem:

• \phi(p,Z) has two nodes as a function of Z (actually the positions are symmetric wrt Z=0)
• The position of the nodes and extrema is moving depending on p
• The matrix phi[:,:] was determined by finding a specific eigenvector for many values of p and storing that vector into the row phi[p,:].

Moving of zeros and extremas of \phi(p,Z) with p:

Since the eigenvectors came from many separate calls to an eigensolver routine, the global sign of each eigenvector is arbitrary. Hence, in the matrix phi it changes for each value of p, i.e. I have many artificial oscillations. As a result the calculation of the second derivative has huge errors.

Arbitrary global sign of \phi(p,Z) with p:

I had a similar problem in the past, however for nodeless eigenfunctions (i.e. they were either purely positive, or purely negative). There, it was easy to enforce the same global sign by dividing by the sign of the function at a specific point, e.g. the central point). However in my current case, the function approaches zero at the edges (i.e. random Â± 1e-16), and the central point can be either a zero or an extremum.

Just to be clear: I understand that this is not a problem of the eigensolver routine, but normal behavior. But does anyone have a good idea how to ensure the same â€śglobalâ€ť sign of \phi, such that the behavior as a function of p is smooth?

Can you find the z_1 \ge 0 that maximizes \phi, and z_2 \ge 0 that minimizes \phi, then change sign if z_1 > z_2?

1 Like

Ah yeah that should be possible. I was thinking of something very complicated, for arbitrary number of nodes. But indeed, for my actual use-case, with a single node for Z\geq 0 your proposed criterion should work. Thanks. I will implement it shortly.