3

This is what I currently have

\begin{figure}[h]
        \centering
        \begin{tikzpicture}
        \begin{axis}[axis equal, axis lines=center,
        xlabel=$\Re$,
        ymax=1.5,ymin=-1.5,
        ylabel={$\Im$},
        domain=-10:10,samples=21,
        disabledatascaling]
        \addplot[scatter,only marks]({cos(3*pi*deg(x)/4)},{sin(3*pi*deg(x)/4)});
        \draw[help lines] (0,0) circle (1);
        \end{axis}
        \end{tikzpicture}
        \caption{\(8^{\rm th}\) roots of unity on \(\mathbb C\)-plane}
        \label{fig:prob3}
\end{figure}

This produces the plot shown below,enter image description here

Could someone explain how I am getting the right angles. How can I change this to plot nth roots of unity for a general n. I am also not sure how to annotate the angles made by the roots with x-axis the right way with pgfplots.

  • 2
    This would be enough. \addplot[scatter, only marks, domain=0:360, samples=9,] ({cos(x)},{sin(x)}); – percusse May 15 '18 at 18:09
4

The code bellow allows you to tune the value of "n" in order to get any number of complex roots, it uses \pgfmathsetmacro in order to fix a value for n.

\documentclass[12pt]{article}
\usepackage{amssymb}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}

\begin{figure}[ht]
        \centering
        \begin{tikzpicture}
        %%%% n is the value setting the number of complex roots
        \pgfmathsetmacro{\n}{7}
        \begin{axis}[axis equal,
        axis lines=center,
        xlabel=$\Re$,
        xtick={-1.5,-0.5,0,0.5,1.5},
        ytick={0,0.5},
        xmax=1.5,
        xmin=-1.5,
        ymax=1.5,
        ymin=-1.5,
        ylabel=$\Im$,
        samples=10,
        disabledatascaling]
        \draw[help lines, black] (0,0) circle (1);
        \foreach \t in {1,...,\n} {
        \edef\temp{\noexpand
        \node[fill=blue, circle, draw=blue, scale=0.5] at ( {cos((360*\t)/\n)}, {sin((360*\t)/\n)} ) {};
         }\temp}
         \foreach \t in {1,...,\n} {
         \edef\temp{\noexpand
         \node[fill=white, circle, draw=none, scale=0.7] at ( {1.25*cos((360*\t)/\n)}, {1.25*sin((360*\t)/\n)} ) {$w_{\t}$};             
          }\temp}
        \end{axis}
        \end{tikzpicture}
        \caption{$n^{th}$ roots of unity on $\mathbb{C}$-plane}
        \label{fig:prob3}
\end{figure}

\end{document}

enter image description here

Another way to obtain the same result is to use \pgfplotsinvokeforeach as a for loop in an axis environement. Although, the variable changing is not \t anymore but #1 like within a macro, see the MWE below:

\documentclass[12pt]{article}
\usepackage{amssymb}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}

\begin{figure}[ht]
        \centering
        \begin{tikzpicture}
        %%%% n is the value setting the number of complex roots
        \pgfmathsetmacro{\n}{7}
        \begin{axis}[axis equal,
        axis lines=center,
        xlabel=$\Re$,
        xtick={-1.5,-0.5,0,0.5,1.5},
        ytick={0,0.5},
        xmax=1.5,
        xmin=-1.5,
        ymax=1.5,
        ymin=-1.5,
        ylabel=$\Im$,
        samples=10,
        disabledatascaling]
\draw[help lines, black] (0,0) circle (1);
\pgfplotsinvokeforeach{1,...,\n}{
\node[fill=blue, circle, draw=blue, scale=0.5] at ( {cos((360* #1)/\n)}, {sin((360* #1)/\n)} ) {};}
\pgfplotsinvokeforeach{1,...,\n}{
\node[fill=white, circle, draw=none, scale=0.7] at ( {1.25*cos((360* #1)/\n)}, {1.25*sin((360* #1)/\n)} ) {$w_{#1}$};}
\end{axis}
\end{tikzpicture}
\caption{$n^{th}$ roots of unity on $\mathbb{C}$-plane}
\label{fig:prob3}
\end{figure}

\end{document}

Hope that it is what you were looking for.

Romain

  • 1
    Very good answer. You picture is fine. +1. – Sebastiano May 15 '18 at 21:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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