4
$\begingroup$

This the code of Hofstadter spectrum for square lattice using Mathematica

 matrix[p_, q_] := Module[{sigma}, sigma = p/q;
   N@SparseArray[{{m_, m_} -> 
       2 Cos[2 Pi*m*p/q], {i_, j_} /; Abs[i - j] == 1 -> 1}, {q, q}]];


 attachsigma[sigma_, lst_] := {sigma, #} & /@ lst

 fracs = 
  Table[p/q, {q, 2, 25}, {p, 2, q}] // Flatten // DeleteDuplicates;

 pq = {Numerator@#, Denominator@#} & /@ fracs;

 ens = Eigenvalues[#] & /@ (matrix[#[[1]], #[[2]]] & /@ pq);

 pts = Flatten[#, 1] &@MapThread[attachsigma, {fracs, ens}];

 
plot = Graphics[{PointSize[0.001], Point[pts]}, AspectRatio -> 1, 
  ImageSize -> 300]
       

in my case, I have a huge matrix $M[p,q]$ I try to do the same thing as this code but it seems that N@SparseArray not useful for me what I'm looking for is: how I should write my input of plotting, my code is quite large just imagine that we have in the end a matrix M that depend on p and q and we need to plot the Hofstadter spectra how we should do this in Mathematica. thanks in advance

$\endgroup$

1 Answer 1

8
$\begingroup$

Just cleaning up your code a little:

matrix[p_, q_] := SparseArray[{Band[{1, 1}] -> 2*Cos[2π*p*Range[q]/q],
                               Band[{1, 2}] -> 1,
                               Band[{2, 1}] -> 1}]
matrix[σ_] := matrix[Numerator[σ], Denominator[σ]]

fracs[qmax_] := Table[p/q, {q, 1, qmax}, {p, 0, q}] // Flatten // DeleteDuplicates

ListPlot[Thread[{#, Eigenvalues[N[matrix[#]]]}] & /@ fracs[100], 
         PlotTheme -> "Scientific", GridLines -> {{1/2}, {0}}]

enter image description here

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.