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 was trying to plot a vectorfield of a gravitational field. I was wondering if there's any way you can set $R = \sqrt{(x-3)^2+(y-3)^2+(z-3)^2}$

Inside the command:

VectorPlot3D[{-((x - 3)/R), -(y - 3)/R, -(z - 3)/R}, {x, -5, 5}, {y, -5, 5}, {z, -5, 5}, VectorScale -> 0.07, VectorPoints -> 10, VectorColorFunction -> Hue]

I searched and couldn't find this. Thanks in advance.

share|improve this question

closed as off-topic by Sjoerd C. de Vries, Mr.Wizard Aug 30 '13 at 22:10

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Sjoerd C. de Vries, Mr.Wizard
If this question can be reworded to fit the rules in the help center, please edit the question.

    
Did you try just using it? r = Sqrt[(x - 3)^2 + (y - 3)^2 + (z - 3)^2]; VectorPlot3D[{-((x - 3)/r), -(y - 3)/r, -(z - 3)/r}, {x, -5, 5}, {y, -5, 5}, {z, -5, 5}, VectorScale -> 0.07, VectorPoints -> 10, VectorColorFunction -> Hue] !Mathematica graphics –  Nasser Aug 30 '13 at 20:12
    
If Hector's reading is correct (and even if it is not) you should see: (559) –  Mr.Wizard Aug 31 '13 at 5:04
add comment

1 Answer 1

up vote 1 down vote accepted

If by "setting variables inside [blah]" you mean specifying temporary values for a symbol while "blah" is evaluated, then you can use With, Block, or Module. Although all these 3 commands would work in your case, there are certain nuances.

With With

With[{R = Sqrt[(x - 3)^2 + (y - 3)^2 + (z - 3)^2]}, 
  VectorPlot3D[{-((x - 3)/R), -((y - 3)/R), -((z - 3)/R)}, {x, -5, 5}, {y, -5, 5}, {z, -5, 5}]]
share|improve this answer
    
Could include Set, SetDelayed, Block, or Module in your answer. Either of these would work. –  Sjoerd C. de Vries Aug 30 '13 at 20:43
1  
@SjoerdC.deVries From the wording of the OP, I understand he wants a temporary assignment. OP wrote "inside the command". Set and SetDelayed would not satisfy that requirement. Module or Block would work. I'll edit the answer –  Hector Aug 31 '13 at 0:44
    
thanks. Come to think of it, how about adding ReplaceAll? –  Sjoerd C. de Vries Aug 31 '13 at 20:41
    
@SjoerdC.deVries: I think ReplaceAll does not hold the arguments the way Set, SetDelayed, Block, Module, and With do. –  Hector Sep 17 '13 at 13:19
    
VectorPlot3D[{-((x - 3)/R), -((y - 3)/R), -((z - 3)/R)} /. R -> Sqrt[(x - 3)^2 + (y - 3)^2 + (z - 3)^2], {x, -5, 5}, {y, -5, 5}, {z, -5, 5}] works for me –  Sjoerd C. de Vries Sep 17 '13 at 21:42
add comment

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