1
$\begingroup$

I want to plot the amplitude of a complex-valued function of one complex variable. I want to do this in the plane defined by the real and imaginary parts of the complex variable as a ContourPlot.

For example, a simple function

$f(z)=\frac{z}{e^{g}-z\,e^{-i\,k}}$

where

$z=\frac{y}{\sqrt{1-y^2+y^4}}\,e^{i\,v}$ is the complex variable, with $1\geq y\geq 0$ and $2\,\pi>v\geq 0$. $g$ and $k$ are some positive constants. I want a plot of $\lvert f(z)\rvert$ as a function of $Re\,(z)$ and $Im\,(z)$ and not as a function of $y$ and $v$.

The only way I know how to do this is using ParametricPlot3D with a function where I explicitly put in the definition of z and figure out its real and imaginary parts to put in as the first two arguments of ParametricPlot3D, that is

fTest2[y_, v_] := (y/Sqrt[1 - y^2 + y^4] E^(I v))/(E^g - y/Sqrt[1 - y^2 + y^4] E^(I v) E^(-I k))

Block[{k = \[Pi]/3, g = 5/10}, 
 ParametricPlot3D[{y/Sqrt[1 - y^2 + y^4] Cos[v],y/Sqrt[1 - y^2 + y^4] Sin[v], Abs[fTest2[y, v]]}, 
{y, 0, 1}, {v, 0,2 \[Pi]}, PlotRange -> All]]

ParametricPlot3DTest

It should be possible to present this as a contour plot, where the height (amplitude of the fucntion) is encoded in the colour of the contour plot. However, I do not know how to do this and would like to learn. The naive exercise of just plugging in the function into ContourPlot leads to

Block[{k = \[Pi]/3, g = 5/10}, 
 ContourPlot[Abs[fTest2[y, v]], {y, 0, 1}, {v, 0, 2 \[Pi] }, 
  PlotRange -> All, PlotLegends -> Automatic]]

ContourPlotTest

which as expected is a plot in terms of y and v and not the real and imaginary parts of z.

$\endgroup$
1
$\begingroup$
f[z_] := z/(Exp[g] - z Exp[-I k])

ComplexContourPlot[
 Abs[Evaluate[f[z] /. {k -> \[Pi]/3, g -> 1/2}]], {z, -1 - I, 1 + I}, 
 PlotRange -> All, Contours -> 8]

Complex contour plot of modulus of a function

The restriction that z = (y/Sqrt[1 - y^2 + y^4])Exp[I v] for 0 <= y <=1 and 0 <= v <= 2 Pi is equivalent to Abs[z] <= 1, so we include the latter RegionFunction restriction in the plot:

 ComplexContourPlot[
    Abs[Evaluate[f[z] /. {k -> \[Pi]/3, g -> 1/2}]], {z, -1 - I, 1 + I}, 
    PlotRange -> All, Contours -> 12, 
    RegionFunction -> Function[{z}, Abs[z] <= 1]]

Complex contour plot with restricted domain

| improve this answer | |
$\endgroup$
  • $\begingroup$ You haven't added the RegionFunction -> Function[{z}, Abs[z] <= 1] part to the arguments of ComplexContourPlot which we reached the conclusion is needed. $\endgroup$ – ThunderBiggi Nov 22 at 9:33
  • $\begingroup$ @ThunderBiggi: your original question didn't ask for such a restriction on z, so far as I can see. $\endgroup$ – murray Nov 23 at 1:29
  • $\begingroup$ If you look at the form of z in terms of y and v and the coordinate ranges for y and v you will realise that there is a restriction on z. Do you understand what is shown with the ParametricPlot3D? $\endgroup$ – ThunderBiggi Nov 24 at 7:52
  • $\begingroup$ @ThunderBiggi: There is a bit of work to be done to show that the restrictions 0 <= y <= 1 and 0 <= v <= 2 \[Pi] on z = v + I y in fact is equivalent to Abs[z]<=1. $\endgroup$ – murray Nov 25 at 16:09
  • $\begingroup$ @ThunderBiggi: The issue with the range of z = y + I v (I had them reversed in previous comment) is that y/Sqrt[1 - y^2 - y^4] becomes nonreal at Sqrt[(Sqrt[5]-1)/2]. $\endgroup$ – murray Nov 25 at 16:45
1
$\begingroup$

If I understand your function correctly, in terms of strictly complex variables, your function is the composite f@z where:

f[z_] := z/(Exp[g] - z Exp[-I k])
z[w_] := Re[w]/Sqrt[1 - Re[w]^2 + Re[w]^4] Exp[I Im[w]]

For the 3D plot we may use the newish ComplexPlot3D function:

ComplexPlot3D[
 Evaluate[f@z[w] /. {k -> \[Pi], g -> 1/2}], {w, 0, 1 + 2 \[Pi] I}]

3D plot of amplitude colored by phase

Then for the desired contour plot of the amplitude use ComplexContourPlot(new in Mathematica 12.1):

Block[{k = \[Pi], g = 1/2},
 ComplexContourPlot[Evaluate[Abs[f@z[w]]], {w, 0, 1 + 2 \[Pi] I}]
 ]

Contour plot of amplitude

| improve this answer | |
$\endgroup$
  • $\begingroup$ Maybe I have not expressed myself clearly. I want a contour plot of $\lvert f(z)\rvert$ as a function of $Re\,(z)$ and $Im\,(z)$. The above produce plots of $f(z)$ as a function of $y$ and $v$. Does that make sense? $\endgroup$ – ThunderBiggi Nov 14 at 23:32
  • $\begingroup$ @ThunderBigg: no, that does not make sense to me, as ostensibly z is a function of y and vOtherwise, what's the point of having your expression for z in terms of y and v? Of course you could just use ComplexContourPlot[Abs[f[z]],...] but then the expression for z in terms of y and v is irrelevant, as are the parameters g and k which enter into the definition of z in terms of y and v! $\endgroup$ – murray Nov 16 at 1:00
  • $\begingroup$ Do you see what is the difference between the result of ParametricPlot3D and the ContourPlot? They both show the amplitude of the function (one through height in 3D the other through changing colours in 2D), but the x- and y-axes represent different things. For ParametricPlot3D you need to have the form of z in order to figure out its real and imaginary parts which are what the x- and y-axes show. On the ContourPlot the x- and y-axes have different ranges since they show y and v. Do you see that difference between the x- and y-axes on the 2 plots in my post? $\endgroup$ – ThunderBiggi Nov 16 at 5:35
  • $\begingroup$ @ThunderBiggi: What function of what complex variable are you really trying to plot. I plotted what your post gave: f[z[v + I y]]. $\endgroup$ – murray Nov 17 at 14:08
  • $\begingroup$ Ok, forget about the definition of z in terms y and v. We just have $f(z)=\frac{z}{e^{g}-z\,e^{-i\,k}}$. Now plot the amplitude of this ($\lvert f(z)\rvert $) as a function of $\mathrm{Re}\,(z)$ and $\mathrm{Im}\,(z)$. $\endgroup$ – ThunderBiggi Nov 17 at 15:47

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.