0
$\begingroup$

I want to calculate the value of $\nabla\cdot\frac{1}{(x^2+y^2+z^2)^{1.5}}(x\hat{x}+y\hat{y}+z\hat{z})$. I used the following syntax:

g[x_, y_, z_] = -x/(x^2 + y^2 + z^2)^1.5;
h[x_, y_, z_] = -y/(x^2 + y^2 + z^2)^1.5;
i[x_, y_, z_] = -z/(x^2 + y^2 + z^2)^1.5;
k[x_, y_, z_] = D[g[x, y, z], x] + D[h[x, y, z], y] + D[i[x, y, z], z]

it output

(3. x^2)/(x^2 + y^2 + z^2)^2.5 + (3. y^2)/(x^2 + y^2 + z^2)^2.5 + ( 3. z^2)/(x^2 + y^2 + z^2)^2.5 - 3/(x^2 + y^2 + z^2)^1.5

which is $\frac{3.\ x^2}{(x^2 + y^2 + z^2)^{2.5}} + \frac{3.\ y^2}{(x^2 + y^2 + z^2)^{2.5}} +\frac{3.\ z^2}{(x^2 + y^2 + z^2)^{2.5}} - \frac{3}{(x^2 + y^2 + z^2)^{1.5}}$.

I tried to simplify the expression with Simplify[%], but nothing changed. I also tried to simplify the part before the -, there is something I can't explain. When I input

Simplify[(3. x^2)/(x^2 + y^2 + z^2)^2.5 + (3. y^2)/(x^2 + y^2 + z^2)^2.5 + ( 3. z^2)/(x^2 + y^2 + z^2)^2.5]

it output

(3. x^2 + 3. y^2 + 3. z^2)/(x^2 + y^2 + z^2)^2.5

which is $\frac{3. x^2 + 3. y^2 + 3. z^2}{(x^2 + y^2 + z^2)^{2.5}}$, but when I input

Simplify[(3 x^2)/(x^2 + y^2 + z^2)^2.5 + (3 y^2)/(x^2 + y^2 + z^2)^2.5 + ( 3 z^2)/(x^2 + y^2 + z^2)^2.5]

by removing the . after 3, the output became

3/(x^2 + y^2 + z^2)^1.5

which is $\frac{3}{(x^2 + y^2 + z^2)^{1.5}}$, and it's what I want. However, if I add the subtracted part like

Simplify[(3 x^2)/(x^2 + y^2 + z^2)^2.5
         +(3 y^2)/(x^2 + y^2 + z^2)^2.5
         + (3 z^2)/(x^2 + y^2 + z^2)^2.5 
         -  3/(x^2 + y^2 + z^2)^1.5]

the result became

3 (x^2/(x^2 + y^2 + z^2)^2.5 + y^2/(x^2 + y^2 + z^2)^2.5 + z^2/(x^2 + y^2 + z^2)^2.5 - 1/(x^2 + y^2 + z^2)^1.5)

which is $3 (\frac{x^2}{(x^2 + y^2 + z^2)^{2.5}} + \frac{y^2}{(x^2 + y^2 + z^2)^{2.5}} + \frac{z^2}{(x^2 + y^2 + z^2)^{2.5}} -\frac{1}{(x^2 + y^2 + z^2)^{1.5}})$.

So how to simplify this expression to the value of 0? Thanks and best regards!

$\endgroup$
  • $\begingroup$ Up to usual conventions, the numbers 0,1,2,3, and 4 are spelled by words in most cases. $\endgroup$ – user64494 Jul 23 at 10:49
1
$\begingroup$

Try

g[x_, y_, z_] = -x/(x^2 + y^2 + z^2)^(15/10);
h[x_, y_, z_] = -y/(x^2 + y^2 + z^2)^(15/10);
i[x_, y_, z_] = -z/(x^2 + y^2 + z^2)^(15/10);
k[x_, y_, z_] = D[g[x, y, z], x] + D[h[x, y, z], y] + D[i[x, y, z], z]

Mathematica graphics

Simplify[%]

gives zero.

Try to use exact numbers when possible.

However, if I add the subtracted part like

Again, you used here exponents which are not exact number. If you use exact numbers, you get this:

Simplify[(3 x^2)/(x^2 + y^2 + z^2)^(25/10) + (3 y^2)/(x^2 + y^2 + z^2)^(25/
   10) + (3 z^2)/(x^2 + y^2 + z^2)^(25/10) - 3/(x^2 + y^2 + z^2)^(15/10)]

Which gives zero.

So how to simplify this expression to the value of 0?

$\endgroup$
  • $\begingroup$ In my calculation, the expression exponents are 1.5 and 2.5, so it is not exactly the same with the example you gave. In your example, you used 25/10 as exponent, but Mathematica seems recognize the /10 as a division in the whole expression. $\endgroup$ – Amon Jul 23 at 6:11
  • $\begingroup$ @Amon, you are right, I need parentheses around the exponents ofcourse. Will correct. Is it OK now? now it gives zero. $\endgroup$ – Nasser Jul 23 at 6:19
  • $\begingroup$ yes, this time it worked! So we'd better use fractions than decimals in Mathematica? $\endgroup$ – Amon Jul 23 at 6:53
  • $\begingroup$ @Amon, in general, when doing symbolic manipulations, rule of thumb I use is to stick to exact numbers/quantities all the time. This makes it easier and less headache for mathematica internal algorithms. If using inexact numbers, then mathematica internally would have to resort to numerical methods sometimes which are not exact ofcourse or makes it not able to do some simplification it could otherwise. Your question is a good example of this. $\endgroup$ – Nasser Jul 23 at 6:57
2
$\begingroup$

Try also this:

vector1 = -(1/(x^2 + y^2 + z^2)^(3/2))*{x, y, z};

Then

Div[vector1, {x, y, z}] // Simplify

(*  0  *)

and

vector2 = -(1/(x^2 + y^2 + z^2)^(5/2))*{x, y, z};

Div[vector2, {x, y, z}] // Simplify

(*  2/(x^2 + y^2 + z^2)^(5/2)  *)

Have fun!

$\endgroup$
  • $\begingroup$ Thank you! It also worked! $\endgroup$ – Amon Jul 23 at 9:48
1
$\begingroup$

You can also use Div in spherical coordinates:

Div[{1/r^2, 0, 0}, {r, θ, φ}, "Spherical"]

0

Alexei's second example using "Spherical" coordinates:

Div[{-1/r^4,0,0},{r,t,g},"Spherical"]

2/r^5

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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