Mathematica Asked by Yduog chan on July 12, 2021
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
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}}]
Answered by Roman on July 12, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP