We have a (Hermitian) matrix of some finite dimension (n) whose elements are functions of real variables x and y. We wish to plot contours of the spectrum (level sets of the n real eigenvalues) at chosen values.
Here's a simple solution using ContourPlot
:
matrix = Table[3 i x + j y, {i, 5}, {j, 5}];
ContourPlot[Sort@Re@Eigenvalues[matrix], {x, -2, 2}, {y, -2, 2},Contours->{0.3, 1.7}] /. _Polygon -> Sequence[]
To be honest, I am not quite sure why this does work--although it does--as the syntax does not appear to follow the documentation for ContourPlot
precisely. Here, the argument of ContourPlot
is an 5-dimensional list of eigenvalues, presumably sampled at some point in the x-y domain. Using PlotPoints
seems to increase the grain size in the domain mesh.
Also, obviously in this example, the eigenvalues have analytic closed-form expressions as functions of x and y, but in my general problem, that is not possible. However, this ContourPlot
method has worked in the past nonetheless.
However, I wish to discretize this process manually using ListContourPlot
. I hope to gain the ability to manually control the domain and mesh size and also make the contour plotting significantly faster (the ContourPlot
version above is quite slow in the real problem).
I am really struggling with the syntax of ListContourPlot
, though. Note that the matrix we examine is given. I need to
- Construct a domain (presumably a
List
ofList
s like {0.234,-0.412}, etc., a list of {x,y} points in the domain). - Numerically evaluate the
Eigenvalues
of the matrix at every point in the domain, and store these results (n-dimensional lists) somehow. - Compile the many eigenvalue lists (one at every site in the discrete domain) into a complex array which fits the syntax for
ListContourPlot
- Perform the
ListContourPlot
and isolated chosen level sets using theContours
option.
The start of a weak working example
matrix = Table[3 i x + j y, {i, 5}, {j, 5}];
domain = Table[{x, y}, {x, -1, 1, 0.5}, {y, -1, 1, 0.5}];
II = Dimensions[domain][[1]];
JJ = Dimensions[domain][[2]];
array = domain;
Do[array[[i, j]] = {array[[i, j, 1]], array[[i, j, 2]],
Sort@Re@Eigenvalues[
ReplaceAll[
matrix, {x -> domain[[i, j, 1]],
y -> domain[[i, j, 2]]}]]}, {i, 1, II}, {j, 1, JJ}]
This is my best effort so far. However, I'm certain that someone can help me find much more elegant solutions to many of these steps.
I build a
domain
using Table, but this could definitely be improved. For example, suppose I wished to use all points (x,y) on a square lattice with some density which lie within aPolygon
instead of a simple rectangle?This point is at least accomplished in
array
, which contains a matrix of lists {x,y,{eigenvalues}}However, this part is a huge failure. The syntax is not commensurable with ListContourPlot in the slightest, so we've really accomplished little.
Please help!