0
$\begingroup$

I'm trying to use Mathematica to get a numerical answer for a physics problem. I define a function $V$ as the sum of three quantities divided by vector norms:

V = (q1 / Norm[r - a] + q2 / Norm[r - b] + q3 / Norm[r - c])

where

a = {2, 4, -3}
b = {-2, 3, -5}
c = {-3, -3, -3}
r = {x, y, z}

I define a new quantity DelDotV = {D[V, x], D[V, y], D[V, z]} Then I plug in 3, 4, 5, for x, y, and z, and 1, -2, 3 for q1, q2, and q3, respectively to get a numerical value, and I'm returned the following: Output

I can infer that these are derivatives of absolute value functions, but I know for a fact the answer is not {0, 0, 0}, so I'm not really looking for the derivatives of absolute value of a constant. What exactly are these and why are they there?

$\endgroup$
3
  • $\begingroup$ Mathematica assumes all variables are complex. If you apply FullSimplify with the added assumption that your variables are real, then the Abs' will disappear. $\endgroup$
    – bill s
    Jan 18, 2016 at 23:49
  • $\begingroup$ You didn't specify q1, q2, q3. $\endgroup$ Jan 18, 2016 at 23:53
  • $\begingroup$ Mathematica doesn't like to take derivatives of the Abs function, which Norm is defined in terms of. Instead of Norm[x], use the explicit form Sqrt[Dot[x, x]]. $\endgroup$
    – march
    Jan 19, 2016 at 0:10

1 Answer 1

2
$\begingroup$

Style recommendation: Never use a variable name starting with an upper-case letter as it may conflict with Mathematica's internal naming convention.

myPotential[q1_, q2_, q3_, r_List, a_List, b_List, c_List] := 
   (q1/Sqrt[Dot[r - a, r - a]] + 
    q2/Sqrt[Dot[r - b, r - b]] + 
    q3/Sqrt[Dot[r - c, r - c]]);

myDelDotPotential[q1_, q2_, q3_, r_, a_, b_, c_] := 
   {D[myPotential[q1, q2, q3, r, a, b, c], x], 
    D[myPotential[q1, q2, q3, r, a, b, c], y], 
    D[myPotential[q1, q2, q3, r, a, b, c], z]};

a = {2, 4, -3};
b = {-2, 3, -5};
c = {-3, -3, -3};
r = {x, y, z};

Simplify@myDelDotPotential[q1, q2, q3, r, a, b, c] /. 
 {x -> 3, y -> 4, z -> 5, q1 -> 1, q2 -> -2, q3 -> 3}

$\left\{\frac{5}{189 \sqrt{14}}-\frac{1}{65 \sqrt{65}}-\frac{18}{149 \sqrt{149}},\frac{1}{189 \sqrt{14}}-\frac{21}{149 \sqrt{149}},\frac{5 \sqrt{\frac{2}{7}}}{189}-\frac{8}{65 \sqrt{65}}-\frac{24}{149 \sqrt{149}}\right\}$

N@%

$\{-0.00473458, -0.0101321, -0.0143207\}$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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