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.
1 Answer
$\begingroup$
$\endgroup$
5
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]
idea2
Manipulate[
VectorPlot[{y - p[[1]], x + p[[2]]}, {x, -3, 3}, {y, -3, 3}],
{{p, {0, 0}}, Locator}]
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]
-
2$\begingroup$ maybe change the points to vectors will have a better visual effect :) very impressive! +1 $\endgroup$– WjxCommented 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$– WjxCommented 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
Animate
andManipulate
function for this. $\endgroup$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$