10
$\begingroup$

I am trying to plot a vector function of a fluid flow given by

$\vec{V} = (\frac{-\cos(\theta)}{r^2},-\frac{\sin(\theta)}{r^2})$

I am trying to plot it in Mathematica using the command below, I converted to Cartesian coordinates by the way. But this does not run in Mathematica. Without the Exclusions option, I only get one arrow at the origin. Can you help me with this plot?

VectorPlot[
      {-(x/(x^2 + y^2)^(3/2)), -(y/(x^2 + y^2)^(3/2))}, 
      {x, -1, 1}, {y, -1, 1}, 
      Exclusions -> {(x^2 + y^2)^(3/2) == 0} 
 ]
$\endgroup$
3
  • 2
    $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the FAQs! 3) When you see good Q&A, 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. ALSO, remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign. $\endgroup$ Commented Oct 21, 2012 at 7:59
  • $\begingroup$ Exclusions is not an option of VectorPlot. If you include it you only get an error message and no plot at all. $\endgroup$ Commented Oct 21, 2012 at 13:26
  • $\begingroup$ This is basically the same as Visualizing a Complex Vector Field near Poles - I'm sure you can adapt one of the answers from that question. $\endgroup$
    – Jens
    Commented Oct 21, 2012 at 17:04

2 Answers 2

13
$\begingroup$

You can make use of option VectorScale - see the "More Information" section, and some singular examples at the end. Setting None will cause all the vectors to have the same length. Or you can improvise with a custom function to make the best view of the arrows (#5 the fifth argument is vector's norm):

VectorPlot[{-(x/(x^2 + y^2)^(3/2)), -(y/(x^2 + y^2)^(3/2))}, {x, -1, 1}, {y, -1, 1},
VectorScale -> {Automatic, Automatic, #}] & /@ {None, Function[If[#5 > 50, None, #5^.3]]}

enter image description here

You can also use StreamPlot

StreamPlot[{-(x/(x^2 + y^2)^(3/2)), -(y/(x^2 + y^2)^(3/2))}, {x, -1, 1}, {y, -1, 1}]

enter image description here

----- Edit: adding potential - as requested in the comments ----------

In your case potential is easily computed as integral over corresponding coordinates. Note automating clipping in the plot range. Here is the result with VectorPlot:

Show[ContourPlot[1/Sqrt[x^2 + y^2], {x, -1, 1}, {y, -1, 1}, 
  ContourStyle -> Directive[Red, Dashed], ColorFunction -> "Rainbow", Contours -> 20],
 VectorPlot[{-(x/(x^2 + y^2)^(3/2)), -(y/(x^2 + y^2)^(3/2))}, {x, -1, 1}, {y, -1, 1}, 
  VectorScale -> {Automatic, Automatic, 
         Function[If[#5 > 50, None, #5^.3]]}, VectorStyle -> Black]]

enter image description here

and StreamPlot styled a bit differently

Show[ContourPlot[1/Sqrt[x^2 + y^2], {x, -1, 1}, {y, -1, 1}, 
  ContourStyle -> Directive[Red, Dashed], ColorFunction -> "GrayTones"],
 StreamPlot[{-(x/(x^2 + y^2)^(3/2)), -(y/(x^2 + y^2)^(3/2))}, {x, -1, 1}, {y, -1, 1}, 
     StreamStyle -> White]]

enter image description here

$\endgroup$
2
  • $\begingroup$ Thanks for this! This is for a fluid flow by the way. Is there an easy way to quickly draw the streamfunction and potential function (prependicular to each other) on the same graph? $\endgroup$
    – l3win
    Commented Oct 21, 2012 at 17:14
  • $\begingroup$ @l3win I updated the post $\endgroup$ Commented Oct 22, 2012 at 0:14
7
$\begingroup$

Exclusions is not an option of VectorPlot. As an alternative, you could use Boole to exclude part of the plot:

VectorPlot[
    Boole[x^2 + y^2 > 0.08] {-(x/(x^2 + y^2)^(3/2)), -(y/(x^2 + y^2)^(3/2))}, 
    {x, -1, 1}, {y, -1, 1}
]

Mathematica graphics

Combining this with the potential:

Show[
 DensityPlot[1/Sqrt[x^2 + y^2], {x, -1, 1}, {y, -1, 1}, 
  ColorFunction -> "SolarColors"],
 VectorPlot[
  Boole[x^2 + y^2 > 
     0.1] {-(x/(x^2 + y^2)^(3/2)), -(y/(x^2 + y^2)^(3/2))}, {x, -1, 
   1}, {y, -1, 1}]
 ]

Mathematica graphics

$\endgroup$
3
  • $\begingroup$ Thank you all for the messages, you have been very helpful. I have one more question. The above was my vector field. Is there any way I can plot the potential function of my vector field? $\vec{V} = \nabla(f)$ How can I plot f? $\endgroup$
    – l3win
    Commented Oct 21, 2012 at 18:34
  • $\begingroup$ I still get a different scalar potential. This seems to me like a single sink, I get a dipole... Thanks for all the replies though $\endgroup$
    – l3win
    Commented Oct 22, 2012 at 16:53
  • $\begingroup$ @I3win have you calculated the gradient of 1/Sqrt[x^2+y^2]? I got the vector field in your code example. The vector plot is consistent with tat, not with te field of a dipole. $\endgroup$ Commented Oct 22, 2012 at 19:09

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.