Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I would like the replacement:

/. {ComplexInfinity -> 0} 

to be treated as a variable.

I am trying to overlay the following list plots:

g1 = (d = (q = 20;
 f = (lop = 
    Transpose[{Flatten[
       Reverse[
         Table[Zeta[y], {y, 0, q}]] /. {ComplexInfinity -> 0}],
      Flatten[Table[x^n, {n, 0, q}]]}];
   {#1*#2} & @@@ lop);
 Flatten[f];
 Total[f]);
sol = Solve[d == 0];
r = ListPlot[{{Re@x, Im@x} /. sol}, AspectRatio -> Automatic, PlotStyle -> Black];
Show[r, PlotRange -> {{-q/10, q/3}, {-q/10, q/10}}, Axes -> False, ImageSize -> 800]);

g2 = (d = (q = 20;
 f = (lop = 
    Transpose[{Flatten[
       Reverse[
         Table[Zeta[y], {y, 0, q}]] /. {ComplexInfinity -> 1}],
      Flatten[Table[x^n, {n, 0, q}]]}];
   {#1*#2} & @@@ lop);
 Flatten[f];
 Total[f]);
sol = Solve[d == 0];
r = ListPlot[{{Re@x, Im@x} /. sol}, AspectRatio -> Automatic, PlotStyle -> Black];
Show[r, PlotRange -> {{-q/10, q/3}, {-q/10, q/10}}, Axes -> False, ImageSize -> 800]);

...

For:

Show[{g1, g2, g3.....}]

Is there an easier way to do this - ie, in a single command?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

How about defining a function:

cplot[m_] := g1 = (d = (q = 20;
 f = (lop = 
    Transpose[{Flatten[
       Reverse[
         Table[Zeta[y], {y, 0, q}]] /. {ComplexInfinity -> m}], 
      Flatten[Table[x^n, {n, 0, q}]]}];
   {#1*#2} & @@@ lop);
 Flatten[f];
 Total[f]);
 sol = Solve[d == 0];
 r = ListPlot[{{Re@x, Im@x} /. sol}, AspectRatio -> Automatic, 
 PlotStyle -> Black];
 Show[r, PlotRange -> {{-q/10, q/3}, {-q/10, q/10}}, Axes -> False, ImageSize -> 800])

Now you get the first plot with cplot[0] and the second with cplot[1]. You can plot many different ones with (for instance)

cplot[#] & /@ Range[5]

which plots the first 5.

share|improve this answer
    
@ Bill s = Many thanks for your help on this - works really well :-) –  martin Nov 4 '13 at 21:01
    
@ Bill s, Is there any way I could use something similar to Show[cplot[Range[5]]]? –  martin Nov 4 '13 at 21:02
    
@ Bill s, Can't seem to get it to work on similar plots...:-/ –  martin Nov 4 '13 at 21:16
1  
I've updated to show you how to make it work on many. You need only define the functions -- be careful of the syntax, note the := and the underscore m_ (two common early mistakes). –  bill s Nov 4 '13 at 22:57
    
@ Bill s, Many thanks - realised resizing issue with other plots - update really useful :-) –  martin Nov 4 '13 at 23:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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