# Plot3D in a loop for Riemann surfaces of the nth-root

I would like to plot the Riemann surfaces for $n$ functions of the form:

$$> f(z) = z^{\frac{1}{n}} = (x + iy)^{\frac{1}{n}}$$

For example for the function

$$> f(z) = z^{\frac{1}{2}}$$

I want it to be:

p2 = Plot3D[{Im[E^[I Pi] (x + I*y)^(1/2)],  Im[E^[2 I Pi] (x + I*y)^(1/2)]},
{x, -2, 2}, {y, -2, 2},
PlotPoints -> {40, 120},
Mesh -> 25,
BoxRatios -> {1, 1, 1},
ColorFunction -> Function[{x, y, z}, Hue[z]],
ImageSize -> size
]


For the function

$$f(z) = z^{\frac{1}{3}}$$

p3 = Plot3D[{Im[(x + I y)^(1/3)], Im[E^(2 I Pi/3) (x + I y)^(1/3)],
Im[E^(4 I Pi/3) (x + I y)^(1/3)]},
{x, -2, 2}, {y, -2, 2},
PlotPoints -> {40, 120},
Mesh -> 25,
BoxRatios -> {2, 2, 2},
ColorFunction -> Function[{x, y, z}, Hue[z]]
]


And so on...

Now, since with growing $n$ the number of imaginary part of the functions grow, so I nested a For loop with a While loop

For[n = 2, n < 4, n++,
f[x_, y_] = (x + I y);
i = 1;
Plot3D[
{
While[i < n + 1,
Im[E^(i I Pi /n) f[x, y]^(1/n)]; i++
]
},
{x, -2, 2},
{y, -2, 2},
PlotPoints -> {40, 120},
Mesh -> 25,
BoxRatios -> {2, 2, 2},
ColorFunction -> Function[{x, y, z}, Hue[z]]
]
]


But this does not produce any output, and I think the bug is in:

       {
While[i < n + 1,
Im[E^(i I Pi /n) f[x, y]^(1/n)]; i++
]
}


as it does not produce a list of

   {Im[E^( I Pi/4) f[x, y]^(1/n)], Im[E^( I Pi/2) f[x, y]^(1/n)], ...}


also, I don't know how to put the comma between the functions Im[E^(i I Pi /n) f[x, y]^(1/n)]...

how can I do?

You can define

riemann[n_] :=
Plot3D[
Evaluate@Table[Im[E^(i I Pi/n) (x + I y)^(1/n)], {i, 1, n + 1}],
{x, -2, 2}, {y, -2, 2},
PlotPoints -> {10, 20},
Mesh -> 5,
BoxRatios -> {2, 2, 2},
ColorFunction -> Function[{x, y, z}, Hue[z]]]

riemann[3]


Or

riemann /@ Range[4]


• Exactly what I was looking for! Aug 8 '17 at 12:55

Let me introduce you to the Table command. This produces a list of the desired plots.

f[x_, y_] := (x + I y);
n = 3;
plotlist = Table[
Plot3D[
Im[E^(i I Pi/n) f[x, y]^(1/n)],
{x, -2, 2}, {y, -2, 2},
PlotPoints -> {40, 120},
Mesh -> 25,
BoxRatios -> {2, 2, 2},
ColorFunction -> Function[{x, y, z}, Hue[z]]
],
{i, 1, n + 1}]


If you like to have all of them in one single plot, you can use Show like this:

Show[plotlist, PlotRange -> All]

• I have a problem with the ColorFunction as the Hue[z] is different for all the $n$ plots.. Aug 8 '17 at 12:51
• You can also use the Table within Plot3D similar to your first try with the While construct. This should fix it. Aug 8 '17 at 19:10