# Animated Vector plot

I'm trying to make an animation of a time-varying 2D vector field. However, I'm got a difficulty in that Mathematica normalises the length of the vectors with each call to VectorPlot.

A (very simple) example:

myField = {Cos[2 π t], 0};

Animate[
VectorPlot[myField /. t -> TT, {x, -1, 1}, {y, -1, 1}],
{TT, 0, 1}]


Expected result: The arrows grow and shrink in time

The actual result: The arrows remain the same size, but flick direction

Is there some way to fix the length of the arrows relative to the field value?

• You've seen VectorScale? Jun 11, 2013 at 13:35

As @Ox4A4D mentioned in the comment, you could use the option VectorScale to set the length of vectors, here is an example code:

myField = {Cos[2 \[Pi] t], 0};
Animate[VectorPlot[myField /. t -> TT, {x, -1, 1}, {y, -1, 1},
VectorScale -> Abs[0.05 Cos[2 Pi TT]]], {TT, 0, 1}]

• Ah, I see -- it's making use of the fact that you know what the maximum value is with this simple function. Perhaps that will put me on the right track... Jun 11, 2013 at 15:04

With a slightly more interesting function, and cleaner syntax:

myField[x_, y_, t_] := {Cos[2 Pi x t], Sin[2 Pi y t]};

Animate[VectorPlot[myField[x, y, t], {x, -1, 1}, {y, -1, 1},
VectorScale -> {Small, 1, None}], {t, 0, 1}]


Check the documentation and play around with the arguments to VectorScale as required.

EDIT:

I had indeed misunderstood your requirements. mm.Jang's answer is what you're looking for. 0.05*Norm[myField[t]] should generalize it.

• Your code somehow doesn't work for me... I'm using MMA 9.0.1.0 by the way...
– Rod
Jun 11, 2013 at 13:53
• Any error? I'm on 9.0.0.0 on 64-bit Linux. Jun 11, 2013 at 13:59
• @RodLm you must run Clear[myField]; first. Jun 11, 2013 at 14:00
• @CoreyKelly Yes, when I run your code nothing happens. I mean, the slider t moves itself but no vector plot is shown.
– Rod
Jun 11, 2013 at 14:00
• @mm.Jang Thank you... problem solved! Corey, please forget what I've written before.
– Rod
Jun 11, 2013 at 14:02