11
$\begingroup$

what codes are needed to properly animate a vector plot? this for example: VectorPlot[{y, -x}, {x, -3, 3}, {y, -3, 3}]. because i tried everything, i have read the help manual, and searched in youtube tutorials but i couldn't do it.

$\endgroup$
5
  • $\begingroup$ What do you mean with animate? What do you want to animate? The vector field you gave is static the only thing there you could animate would be plot parameters or the field itself. Mathematica has the Animate and Manipulate function for this. $\endgroup$
    – N0va
    Commented Aug 30, 2016 at 21:48
  • $\begingroup$ My teacher just told us to make a vector field 2D and 3D to move ("animate"), but i have never used mathematica before. $\endgroup$
    – Arturo
    Commented Aug 30, 2016 at 21:50
  • 2
    $\begingroup$ Look at the Documentation for Animate and put in your vector plot instead of the normal plot from the example. Then you just need to chose what quantity you want to animate. The field itself could be one option: Animate[VectorPlot[{y, u*x}, {x, -3, 3}, {y, -3, 3}], {u, -2, 2}] $\endgroup$
    – N0va
    Commented Aug 30, 2016 at 21:56
  • $\begingroup$ thanks really, yes thats exactly what i didn't know how to do it. $\endgroup$
    – Arturo
    Commented Aug 30, 2016 at 22:00
  • $\begingroup$ Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. $\endgroup$
    – bbgodfrey
    Commented Aug 30, 2016 at 22:25

1 Answer 1

16
$\begingroup$

Here is one possibility:

Clear[dx, dy, f, points, fmap, stages, stuff]

dx[x_, y_] := -9 y + (3 x^2 y)/4;
dy[x_, y_] := -9 x + x^3/4;
Clear[f]
f[{x_, y_}] := {0, 0} /; \[Not] (-10 <= x <= 10.1);
f[{x_, y_}] := {0, 0} /; \[Not] (-10 <= y <= 10.1);
f[{x_, y_}] := {x + .001 dx[x, y] , y + .001 dy[x, y]};


 points = Partition[Table[RandomReal[{-4, 4}], 200], 2, 1]~Join~
          Partition[Table[RandomReal[{-10, 10}], 200], 2, 1];




  Clear[fmap];
  fmap[{stuff___}] := f /@ {stuff};
  stages = NestList[fmap, points, 100];
  stages = stages /. {x_Real, y_Real} /; \[Not](-10 < x < 10) :>{0,0};



    stuff = Show[StreamPlot[{-9 y + (3 x^2 y)/4, -9 x + x^3/4}, {x, -10, 10}, {y, -10, 10}, 
    PlotTheme -> "Minimal"],
    Graphics@{Red, PointSize[.015], Point[stages[[hh]]]},
    PlotRange -> {{-10, 10}, {-10, 10}}
    , Axes -> True]~Table~{hh, 1, 100, 1};


    ListAnimate[stuff]

enter image description here

enter image description here

idea2

 Manipulate[
  VectorPlot[{y - p[[1]], x + p[[2]]}, {x, -3, 3}, {y, -3, 3}],
  {{p, {0, 0}}, Locator}]

another one enter image description here enter image description here

Clear[dx, dy, f, points, fmap, stages, stuff]

dx[x_, y_] := y^3 - 9 x ;
dy[x_, y_] := x^3 - 9 y ;

f[{x_, y_}] := {0, 0} /; \[Not] (-10 <= x <= 10.1);
f[{x_, y_}] := {0, 0} /; \[Not] (-10 <= y <= 10.1);
f[{x_, y_}] := {x + .001 dx[x, y], y + .001 dy[x, y]};

points = Partition[Table[RandomReal[{-4, 4}], 200], 2, 1]~Join~
         Partition[Table[RandomReal[{-10, 10}], 200], 2, 1];


fmap[{stuff___}] := f /@ {stuff};
stages = NestList[fmap, points, 100];
stages = stages /.{x_Real, y_Real} /; \[Not] (-10 < x < 10) :> {0,0};


stuff = Show[
    StreamPlot[
         {    y^3 - 9 x   ,     x^3 - 9 y  },
         {x, -10, 10},
         {y, -10, 10},
         PlotTheme -> "Minimal"
       ],
         Graphics@{Red, PointSize[.015], Point[stages[[hh]]]}, 
         PlotRange -> {{-10, 10}, {-10, 10}},
         Axes -> True
 ]~Table~{hh, 1, 100, 1};


 ListAnimate[stuff] 
$\endgroup$
5
  • 2
    $\begingroup$ maybe change the points to vectors will have a better visual effect :) very impressive! +1 $\endgroup$
    – Wjx
    Commented Aug 30, 2016 at 23:42
  • $\begingroup$ good idea! I will try to do that. @Wjx $\endgroup$ Commented Aug 31, 2016 at 20:38
  • 1
    $\begingroup$ Also, you can ramdomly generate points in the animation process, so the dynamic can keep going. $\endgroup$
    – Wjx
    Commented Aug 31, 2016 at 22:20
  • 1
    $\begingroup$ falstad.com/vector probably the best simulation on the internet $\endgroup$ Commented Aug 15, 2019 at 17:21
  • $\begingroup$ another nice javascript simulation anvaka.github.io/fieldplay $\endgroup$ Commented Aug 15, 2019 at 22:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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