Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
1  
You've seen VectorScale? –  J. M. Jun 11 '13 at 13:35
add comment

2 Answers

up vote 5 down vote accepted

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}]
share|improve this answer
    
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... –  Eoin Jun 11 '13 at 15:04
add comment

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.

share|improve this answer
    
Your code somehow doesn't work for me... I'm using MMA 9.0.1.0 by the way... –  Rod Jun 11 '13 at 13:53
    
Any error? I'm on 9.0.0.0 on 64-bit Linux. –  Corey Kelly Jun 11 '13 at 13:59
    
@RodLm you must run Clear[myField]; first. –  mm.Jang Jun 11 '13 at 14:00
1  
@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 '13 at 14:00
2  
@mm.Jang Thank you... problem solved! Corey, please forget what I've written before. –  Rod Jun 11 '13 at 14:02
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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