2
$\begingroup$

I'm starting to read chapter 11 of Stan Wagon's third edition of Mathematica in Action, a section written by Mark McClure (and there is a package for the notebook).

I start with:

f[z_] := z^2;
Subscript[z, 0] = 0.9 + 0.15 I;
orbit = NestList[f, Subscript[z, 0], 10]

Then:

Attributes[ComplexTicks] = Listable;
ComplexTicks[s_?NumericQ] := {s, s I} /. 
  Thread[{-1. I, 0. I, 1. I} -> {-I, 0, I}]

What this does, I believe, is create a list of tick marks drawn with the specified labels. For example:

ComplexTicks[Range[0, .4, 0.1]]

Produces:

{{0., 0}, {0.1, 0. + 0.1 I}, {0.2, 0. + 0.2 I}, {0.3, 0. + 0.3 I}, {0.4, 0. + 0.4 I}}

So, for example, at 0.0 we'll mark with 0; at 0.1 we'll mark with 0.+0.1I; etc. Now, his next code is:

ListPlot[{Re[#], Im[#]} & /@ orbit, Frame -> True,
 FrameTicks -> {Automatic, ComplexTicks[Range[0, 0.4, 0.1]], None, 
   None}]

Which is supposed to produce this image:

enter image description here

But that was in an older version of Mathematica. In Mathematica 11.1.1, it produces this image.

enter image description here

The current way to set FrameTicks in Mathematica is FrameTicks->{{left, right},{bottom, top}}. So I adjusted the code as follows:

ListPlot[{Re[#], Im[#]} & /@ orbit, Frame -> True,
 FrameTicks -> {{ComplexTicks[Range[0, 0.4, 0.1]], None}, {Automatic, 
    None}}]

But that gives this image:

enter image description here

Any way to turn off the real zeros in each complex tick number?

Update: Thanks to the help from my colleagues, I gave this a try.

Attributes[ComplexTicks] = Listable;

ComplexTicks[s_?NumericQ] := {s, s "\[ImaginaryI]"} /. 
  Thread[{-1. "\[ImaginaryI]", 0. "\[ImaginaryI]", 
     1. "\[ImaginaryI]"} -> {-I, 0, I}]

f[z_] := z^2;
z0 = 0.9 + 0.15 I;
orbit = NestList[f, z0, 10];

ListPlot[{Re[#], Im[#]} & /@ orbit, Frame -> True,
 FrameTicks -> {{ComplexTicks[Range[0, 0.4, 0.1]], None}, {Automatic, 
    None}}]

The resulting image is next:

enter image description here

Any thoughts?

$\endgroup$
4
$\begingroup$

At some point, Mathematica started showing the real part in inexact complex numbers. To workaround this, I would change ComplexTicks to something like:

ComplexTicks[s_?NumericQ] := {s, s Defer[I]}

or

ComplexTicks[s_?NumericQ] := {s, s HoldForm[I]}
$\endgroup$
  • 1
    $\begingroup$ Or: ComplexTicks[s_?NumericQ] := {s, s "\[ImaginaryI]"}. $\endgroup$ – Jens Jul 17 '17 at 19:31
0
$\begingroup$

If it's just a visualization requirement, perhaps you could use:

ComplexTicks[s_?NumericQ] := {s, ToString[s] <> ToString[" \[ImaginaryI]"]}

Mathematica graphics

$\endgroup$
  • $\begingroup$ That would produce some pretty horrifying output for ComplexTicks[10^-1] or ComplexTicks[.000001]. $\endgroup$ – Carl Woll Jul 17 '17 at 18:41
  • $\begingroup$ @CarlWoll Yep, you're right, it would. $\endgroup$ – MarcoB Jul 17 '17 at 19:33

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.