4
$\begingroup$

I would like to draw a vector field and let the magnitude of the vectors change over time (t) using the Manipulate function. The direction of the vectors will be static.

Manipulate[
 VectorPlot[{Cos[t]*(-y), Cos[t]*x}, {x, -1, 1}, {y, -1, 1}]
 , {t, 0, 2 Pi}]

You can see that Cos[t] is the factor i use to scale the vectors. By default the plotted vectors all have the same length and a color function is used to indicate magnitude. However, i would like to have the magnitude represented by the length of the vectors, not by color. If i use VectorScaling, the vectors are scaled independently for every frame so if i play the animation there will be no change visible until the orientation switches. I would like to see the length of the vectors change over time. Is there an easy way to do this?

Any help will be greatly appreciated.

Greetings,

Fabian.

$\endgroup$
1
  • 1
    $\begingroup$ What version are you using? See VectorScale and follow the links if you're using V12.1 or later. (VectorPlot was changed significantly, so the version is important.) $\endgroup$
    – Michael E2
    Commented Nov 26, 2020 at 16:55

1 Answer 1

4
$\begingroup$

For version V12.1. I couldn't figure out a way to get VectorScaling to do anything except the limited options listed in the docs. (The old VectorScale seemed simultaneously more versatile and inscrutable.)

interp[p_, q_, s_] := ( p (1 - s) + q (1 + s))/2;
Manipulate[
 VectorPlot[{Cos[t]*(-y), Cos[t]*x}, {x, -1, 1}, {y, -1, 1},
   VectorScaling -> Automatic] /. 
  Arrow[{p_, q_}] :> 
   Arrow[{interp[p, q, -Abs@Cos[t]], interp[p, q, Abs[Cos[t]]]}],
 {t, 0, 2 Pi}]

enter image description here

Note that the rescaling by VectorPlot still makes the scaling by Cos[t] irrelevant, except for the sign of Cos[t]. One could omit the Cos[t] from the vector field and the Abs from the interpolation and get the same plot.

$\endgroup$
1
  • $\begingroup$ Thank you so much for your help! $\endgroup$
    – kienappel
    Commented Nov 26, 2020 at 18:06

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.