4
$\begingroup$

Below is my current code. I have tried to plot Points 2 in the complex plane using suggestions from prior questions, but am still having some difficulties achieving a plot (Also, if there is a cleaner way to do any of the following steps, I am open to suggestions). My current plots are blank.

MA = 2
MB = 5 
ma = MA/(MA + MB)
mb = MB/(MB + MA)
a = 5
phivals = Table[i, {i, 0, 2 π, π/100.}];
Points1 = {};
Do[Points1 = 
Append[Points1, {phivals[[i]], 
NSolve[{ma/(z - a)^2 + mb/(z + a)^2 == 
Exp[I  φ] /. {φ -> phivals[[i]]}}, 
z]}], {i, Length[phivals]}]
Points2 = Catenate[Thread /@ (Points1 /. r == v_ :> v /. Or -> List)]

This is one of my attempts to plot the points...

ListPolarPlot[{Re[Points2], Im[Points2]}, PlotRange -> All]

This is my second attempt to plot the points...

p = ListPolarPlot[{Re[#], Im[#]} & /@ Points2, AxesOrigin -> {0, 0}, 
PlotRange -> All, ImagePadding -> 40, AspectRatio -> 1, 
Frame -> True, FrameLabel -> {{Im, None}, {Re, "complex plane"}}, 
PlotStyle -> Directive[Red, PointSize[.02]]]; Show[p]

Here are a couple of the points...

{{0., {z -> -5.84618}}, {0., {z -> 5.53625}}, {0., {z -> 
4.46333}}, {0., {z -> -4.1534}}, {0.0628319, {z -> -5.84576 + 
0.0266388 I}}, {0.0628319, {z -> 
5.53598 - 0.0169473 I}}, {0.0628319, {z -> 4.46361 + 0.0170001 I}}
$\endgroup$
5
$\begingroup$

Does this do what you want?

Points2 = Catenate[Thread[{#, z /. #2}] & @@@ Points1];

ListPolarPlot[{Re[Points2], Im[Points2]}, PlotRange -> All]

enter image description here

Or maybe:

ListPolarPlot[ReIm @ Points2, PlotRange -> All]

enter image description here


By the way you should avoid Do with Append in most cases, and use Table instead. You can also iterate over a list directly. You can write:

Points2 =
  Table[Thread @ {φ, 
      z /. NSolve[{ma/(z - a)^2 + mb/(z + a)^2 == Exp[I φ]}, 
        z]}, {φ, phivals}] // Catenate;
$\endgroup$
1
  • $\begingroup$ Getting closer, thanks for your help. I goofed and realized I am only to plot the z values. $\endgroup$ – Astroturf Jul 2 '17 at 15:33
3
$\begingroup$

A quick fix:

ListPolarPlot[{Re[#], Im[#]} & /@ (Flatten@Points1 /. Rule[_, c_] -> c),
 AxesOrigin -> {0, 0},
 PlotRange -> All,
 ImagePadding -> 40,
 AspectRatio -> 1,
 Frame -> True,
 FrameLabel -> {{Im, None}, {Re, "complex plane"}},
 PlotStyle -> Directive[Red, PointSize[.02]]]

enter image description here

A better and faster solution (like Mr. Wizard already noted) would be to use Table. Also, you don't need to precompute phivals:

fun = ma/(z - a)^2 + mb/(z + a)^2 == Exp[I \[CurlyPhi]];

tab = Flatten@Table[z /. NSolve[fun, z], {\[CurlyPhi], 0, 2 Pi, Pi/100.}]

and then

 ListPolarPlot[{Re[#], Im[#]} & /@ tab ...]
$\endgroup$
1
  • $\begingroup$ Thank you very much! $\endgroup$ – Astroturf Jul 2 '17 at 21:00

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.