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


closed as off-topic by Michael E2, Henrik Schumacher, m_goldberg, Bill Watts, José Antonio Díaz Navas Feb 16 at 11:39

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Michael E2, Henrik Schumacher, m_goldberg, Bill Watts, José Antonio Díaz Navas
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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 at 2:52

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_, \[Theta]_] := {r^2 + Cos[m \[Theta]], r^2 - Sin[m \[Theta]]};

mc[m_, x_, y_] := Evaluate@TransformedField["Polar" -> "Cartesian", mp[m, r, \[Theta]], {r, \[Theta]} -> {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

  • $\begingroup$ You might also consider to post the corrected code in copyable form. $\endgroup$ – Henrik Schumacher Feb 13 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 at 1:57
  • $\begingroup$ Copy (right-click->As Input) and paste does not work? $\endgroup$ – Henrik Schumacher Feb 13 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 at 2:07
  • $\begingroup$ Anyways, you've already got my upvote. Welcome on Mathematica.StackExchange! $\endgroup$ – Henrik Schumacher Feb 13 at 2:22

Here we can get beautiful pictures

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


  • $\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 at 0:55
  • $\begingroup$ This is an interesting vector field. Perhaps the author will explain what it describes. $\endgroup$ – Alex Trounev Feb 14 at 1:20

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