0
$\begingroup$

I'm trying to plot the following function for two different values of variable m. However, it seems the second figure never appears. Weirdly, I noticed that real numbers are being attributed to variables x and y.

mp[m_, r_, θ_] := {r^2 + Cos[m θ],r^2 - Sin[m θ]};
mc[m_, x_, y_]:=
  Evaluate @ TransformedField["Polar" -> "Cartesian", mp[m, r, θ], {r, θ} -> {x, y}];

{VectorDensityPlot[mc[0, x, y], {x, -5, 5}, {y, -5, 5}], 
 VectorDensityPlot[mc[1, x, y], {x, -5, 5}, {y, -5, 5}]}

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ If I use the code in the image -- it seems the posted code has a theta missing the brackets, \Theta instead of \[Theta], the latter being what it shown in the image of the code -- it works and give a correct plot for both. $\endgroup$
    – Michael E2
    Feb 13, 2019 at 2:52

2 Answers 2

7
$\begingroup$

Please make sure your "thetas" are consistent. After changing all the thetas, I seem to have gotten your code to work. Please see the linked figure.

mp[m_, r_, θ_] := {r^2 + Cos[m θ], r^2 - Sin[m θ]};

mc[m_, x_, y_] :=
   Evaluate @ TransformedField["Polar" -> "Cartesian", mp[m, r, θ], {r, θ} -> {x, y}];

{VectorDensityPlot[mc[0, x, y], {x, -5, 5}, {y, -5, 5}],
 VectorDensityPlot[mc[1, x, y], {x, -5, 5}, {y, -5, 5}]}

Vector Density Plots

$\endgroup$
8
  • $\begingroup$ You might also consider to post the corrected code in copyable form. $\endgroup$ Feb 13, 2019 at 1:10
  • $\begingroup$ Thanks for the suggestion. I must be missing something but had to insert the code line-by-line. Okay, only three lines! But it could get tedious. Probably there is a way to insert all the code at once, yes? $\endgroup$
    – mjw
    Feb 13, 2019 at 1:57
  • $\begingroup$ Copy (right-click->As Input) and paste does not work? $\endgroup$ Feb 13, 2019 at 1:59
  • $\begingroup$ I tried that. Didn't quite work. The first two lines were copied correctly with proper indentation. The third line was not. $\endgroup$
    – mjw
    Feb 13, 2019 at 2:07
  • $\begingroup$ Anyways, you've already got my upvote. Welcome on Mathematica.StackExchange! $\endgroup$ Feb 13, 2019 at 2:22
3
$\begingroup$

Here we can get beautiful pictures

    mp = {r^2 + Cos[m*θ], r^2 - Sin[m*θ]}; 
    mc = TransformedField["Polar" -> "Cartesian", 
       mp, {r, θ} -> {x, y}]; 
Table[VectorDensityPlot[mc, {x, -2, 2}, {y, -2, 2}, 
  PlotLabel -> Row[{"m = ", m}], ColorFunction -> Hue, 
  StreamPoints -> Fine], {m, 0, 9}]

fig1

$\endgroup$
2
  • $\begingroup$ This is very nice! For m=7, for example, we see a regular heptagon and one of the heptagrams indicated in your figure. I wonder what it would take to see the other one (or is it somehow already in the picture?). [Weisstein, Eric W. "Heptagram." From MathWorld--A Wolfram Web Resource.] (mathworld.wolfram.com/Heptagram.html) $\endgroup$
    – mjw
    Feb 14, 2019 at 0:55
  • $\begingroup$ This is an interesting vector field. Perhaps the author will explain what it describes. $\endgroup$ Feb 14, 2019 at 1:20

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