I've got a real nasty function that I can't figure out how to plot.
The function is
$\qquad f(k) = \pm\sqrt{1+4\cos^{2}(k/2)+4\cos(k/2)\cos(p)}$
from $k=-\pi$ to $k=\pi$, which doesn't look so bad, except $p$ is all the roots of
$\qquad \sin(pn)+2\cos(k/2)\sin(p(n+1))$
where $0<p<\pi$. There are $n$ or $n-1$ such solutions for $p$, and they depend on $k$, and I need to plot the lines for the different values of $p$ all on the same plot. I get to choose the value of $n$, which is an integer, probably around 30.
The way I've tried to do this so far is to start $k$ off at $-\pi$, slowly increment it towards $\pi$, and at each step, work out the values of $p$, and then plot those specific points for that $k$ and the corresponding $p$'s. By making the steps small enough, I get points close enough together that they look like a solid line. However, this approach is horribly slow and feels wrong. Is there a better way to go about this, preferably one where I end up with actual curves and not just a bunch of points?
Also, the function clearly has mirror symmetries, where the axes of symmetry are the axes of the plot. Is there some way to work out the plot for just the top right quadrant, and then mirror it onto the other three quadrants?
This function describes energy bands in graphene nanoribbons with zigzag edges. See Appendix B here for details.