0
$\begingroup$

I am trying to do a vector plot of a given vector field for which I wrote following code

f[x_, y_, z_] := 1/Sqrt[x^2 + y^2 + z^2] + 1/Sqrt[(x - 1)^2 + y^2 + z^2] + 1/Sqrt[(x - 1)^2 + (y -1)^2 + z^2] + 1/Sqrt[x^2 + (y - 1)^2 + z^2] + 1/Sqrt[x^2 + y^2 + (z - 1)^2] + 1/Sqrt[(x - 1)^2 + y^2 + (z - 1)^2] + 1/Sqrt[(x - 1)^2 + (y - 1)^2 + (z - 1)^2] + 1/Sqrt[x^2 + (y - 1)^2 + (z - 1)^2]
VectorPlot3D[Grad[f[x, y, z], {x, y, z}], {x, -1, 1}, {y, -1, 1}, {z, -1, 1}]

But I'm getting following output enter image description here

Where am I making the mistake and I have also tried restarting the kernel?

Edit: I got around the problem by going through the method of tables. The code is:

f[x_, y_, z_] := 1/Sqrt[x^2 + y^2 + z^2] + 1/Sqrt[(x - 1)^2 + y^2 + z^2] + 1/Sqrt[(x - 1)^2 + (y -1)^2 + z^2] + 1/Sqrt[x^2 + (y - 1)^2 + z^2] + 1/Sqrt[x^2 + y^2 + (z - 1)^2] + 1/Sqrt[(x - 1)^2 + y^2 + (z - 1)^2] + 1/Sqrt[(x - 1)^2 + (y - 1)^2 + (z - 1)^2] + 1/Sqrt[x^2 + (y - 1)^2 + (z - 1)^2]
h = Grad[f[x, y, z], {x, y, z}];
vectors = Table[-h, {x, -0.13, 1.13, 0.05}, {y, -.13, 1.13, 0.05}, {z, -.13, 1.13, 0.05}];
ListVectorPlot3D[vectors, VectorScale -> {Small, 0.6, Automatic}, VectorColorFunction -> "Rainbow", PerformanceGoal -> "Quality"]

and the output looks like: c

$\endgroup$

1 Answer 1

1
$\begingroup$

Try

VectorPlot3D[Evaluate@Grad[f[x, y, z], {x, y, z}], 
      {x, -1, 1}, {y, -1, 1}, {z, -1,1}]

enter image description here

$\endgroup$
3
  • $\begingroup$ Nope I'm still getting the same single vector in the output. $\endgroup$
    – aitfel
    Commented Apr 3, 2020 at 5:38
  • $\begingroup$ @aitfel I am sorry to hear that. But as you can see, it works for me. May be version difference. I could try on what I have, which is V 12.1 $\endgroup$
    – Nasser
    Commented Apr 3, 2020 at 5:50
  • $\begingroup$ I did get the result but by using ListVectorPlot3D $\endgroup$
    – aitfel
    Commented Apr 3, 2020 at 6:26

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.