14
$\begingroup$

I have tried the following code:

ParametricPlot[{Sin[12 u] Cos[u], Sin[12 u] Sin[u]}, {u, 0, 2 Pi}]

and it produced the following image:

Flower

MATLAB has a comet command that will draw this parametric plot in real time, allowing the viewer to watch as the particle traces out the plot. Is there a way to do this in Mathematica?

$\endgroup$
0
12
$\begingroup$

You can use Animate, you'll note that I added some options, remove them to see why :)

Animate[
 ParametricPlot[{Sin[12 u] Cos[u], Sin[12 u] Sin[u]}, {u, 0, umax},
  PlotRange -> {-1, 1},
  PerformanceGoal -> "Quality"],
 {umax, 0.1, 2 Pi}]

You can change Animate to Manipulate if you wish to slide back and forth manually as well

$\endgroup$
1
  • 1
    $\begingroup$ Animate seems like Manipulate in many ways, it allows manual control of the slider as well, it merely starts it running automatically. $\endgroup$
    – BoLe
    Jul 31 '16 at 7:16
16
$\begingroup$
frames = Table[
  ParametricPlot[{Sin[12 u] Cos[u], Sin[12 u] Sin[u]}, {u, 0, t}, 
   PlotRange -> {{-1, 1}, {-1, 1}}], {t, .001, 2 Pi, 2.1 Pi/100}]

and then either

ListAnimate[frames]

or

Export["movie.gif", frames]

depending on what you want. The latter yields

enter image description here

You can also do this:

 Manipulate[ParametricPlot[{Sin[12 u] Cos[u], Sin[12 u] Sin[u]}, {u, 0, t}, 
       PlotRange -> {{-1, 1}, {-1, 1}}], {t, .01, 2 Pi}]
$\endgroup$
2
  • $\begingroup$ I just went back and applied this to some of my diff. eq. homework and this is amazing. Thank you! $\endgroup$
    – Reid
    Dec 27 '12 at 23:51
  • $\begingroup$ @Reid: Glad to help! $\endgroup$
    – JohnD
    Dec 28 '12 at 1:11
4
$\begingroup$

Unchecked :

 Needs["NETLink`"]
 m = CreateCOMObject["matlab.application"]

 m@Execute["t = 0:.01:2*pi;
            x = sin(12*t).*(cos(t));
            y = sin(12*t).*(sin(t));
            comet(x,y);"]

First seen this here.

$\endgroup$
2
$\begingroup$

The more MATLAB-like solution:

Animate[
 Show[
  ParametricPlot[{Sin[4 x] Cos[x], Sin[4 x] Sin[x]}, {x, 0, y},
   PlotRange -> {{-1, 1}, {-1, 1}}], 
  ParametricPlot[{Sin[4 z] Cos[z], Sin[4 z] Sin[z]}, 
   {z, y - 0.02 \[Pi], y}, PlotStyle -> Directive[Red, Thick]], 
  Graphics[{Red, AbsolutePointSize[8],
   Point[{Sin[4 y] Cos[y], Sin[4 y] Sin[y]}]}]],
 {y, 0, 2 \[Pi],0.001 \[Pi]}
]

Here's the gif output:

enter image description here

Personally I prefer that the full orbital be kept as background with comet moving on it. In that case I change the parameter maximum to 2[Pi] instead of y, in the first ParametricPlot. (I use angular frequency 4 instead of 12 to make the animation smoother. If you raise the angular frequency, you should use more points, that is, smaller step, in animation so that it is smooth enough. Otherwise it looks silly to use comet plot.)

$\endgroup$

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.