# Plotting eigenvalues depending on their locations

I have a finite chain (say $N$) which can be represented by a matrix(for e.g. a chain of $l$ atoms per unit cell, then it will be $(l\times N)$ $\times$ $(l\times N)$, this matrix depends on some parametrs. Now, my job is to find the eigenvalues and eigenvectors of these matrix, which is pretty simple job. However, now my system is finite so it has beginning and end (beginning and end of the chain of size $N$) . So, my job is to find them but in a special way.
What I need to plot is, plotting the eigenvalues with respect to these parameters. But the values corresponding to the boundaries(or which lives on the ends) of the finite system will be plotted with different color. How to achieve this?

What i think can work (an idea not original to me)
I take the normalized eigenvectors($\psi$) and then calculate the position expectation($\psi^{*}_{m} m \psi_{m}$ and then use it for ColorData, which shows the different color for the end states and same for the states in the middle.
Is there a better a way? How it can be implemented? Thanks a lot, I am stuck and not able to implement it in the Mathematica language(which I explained above)...
Example:
We have nearest hopping for $N =4$ and two atoms in unit cell(where, with in unit cell we have hopping $t1$ and outside $t2$). Chain is like, for e.g $1-2--3-4--5-6--7-8$(where $'-'$ : $t1$ and $'--'$ : $t2$)
Hamiltonian(in the basis of atomic positions) is:

H={{0,t1,0,0,0,0,0,0},{t1,0,t2,0,0,0,0,0},{0,t2,0,t1,0,0,0,0},...;
evg=Eigenvalues[H];
Ev=Eigenvectors[H];


Now evg has 8 eigenvalues and 8 eigenvectors. For some choice($t2>t1$ not equal 0) of $t1$, and $t2$ we have states near the edge. I want to plot the eigenvectors with respect say t2(from 0 to 2) by fixing t1(say 1). Then the color for states at the edges is different from the states not at the edge.

• Let me get this straight. You wish to color-code the plotted lines of the eigenvalues as functions of t2 for t1 == 1 according to the position expectation values? Mar 13, 2018 at 12:38
• It appears, perhaps unsurprisingly, that the expectation value is always in the middle. Perhaps you're more interested in a measure of the distance from the center, such as $\psi_m^* (m-4.5)^2 \psi_m$? Mar 13, 2018 at 12:48
• @LLlAMnYP Ya, I wish to color them as per the position. However, it was just a thought to distinguish the states at the end points from the states not at the end points, which can be changed, as you mentioned in the second comment, I didn't think about that.
– L.K.
Mar 13, 2018 at 13:10
• Here's something to get you started, I'm using the expression from my comment. Mar 13, 2018 at 13:15

In any case, here's approximately how to do this:

mat = SparseArray[{{i_, j_} /;
Abs[i - j] == 1 :> (Mod[j + i, 4] - 2)*(t - 1.)/2 + (1 + t)/
2}, {8, 8}] // Normal // Expand
{ev, evec} = Eigensystem[mat];


Mathematica conveniently can give a solution in terms of roots of 8th-order polynomials here. Since the solution is analytical, it is not automatically normalized. So the code below takes care of that.

Do[eigVal[i, t_] := Evaluate@ev[[i]];
eigVec[i, t_] := Evaluate@evec[[i]];, {i, 8}]
expec[i_Integer, t_] := (Normalize[eigVec[i, t]]^2).(Range - 4.5)^2


The above makes the dependences on t explicit. expec is the mean-square distance from the center of the chain.

A brief inspection allows to conclude that the mean-square-distances lie between 2.25 and 12.25. I plot half of the solutions, since the remaining half are the same, but with negated eigenvalues.

Table[Plot[eigVal[i, t], {t, 0.1, 5},
ColorFunction -> (ColorData[
"Rainbow"][.1 (-2.25 + expec[i, #1])] &),
PlotRange -> {-6, 6}, ColorFunctionScaling -> False], {i, 5,
8}] // Show Red is close to the edge, purples are close to the middle.

• It is going along the same line, very promising. Is there way to color other states the same color, say green? Just to make the separation completely distinct Sorry to bother you again
– L.K.
Mar 13, 2018 at 13:49
• @L.K. each of the states can be further from or closer to the edge, though some do tend to be closer to the middle. There's always the option of classifying them by the distance at low t, but at higher t they tend to smear out. Mar 13, 2018 at 13:58
• Ok, But the calculation of {ev, evec} = Eigensystem[mat];, is very expensive for large size(as 8 was just an example) because of presence of a variable. Is there way to get around? I already tried 20 size it start to take more time and seems to slow down a lot(more than that it is very unfeasible, sorry these were just genuine remarks, I liked your solution just trying to see much better version :).
– L.K.
Mar 13, 2018 at 14:02
• May be finding the mean-square-distances can be time consuming and complicated task for large system.
– L.K.
Mar 13, 2018 at 14:11
• @L.K. if the evaluation eventually finishes for a larger matrix, it is of course better to use that. If not, one can numerically calculate the eigensystem for a given numeric t (this is relatively fast). The drawback is that the ordering of the eigenvalues/eigenvectors can change (especially true if eigenvalues intersect at some t`). Mar 13, 2018 at 18:13