5
$\begingroup$

I am a new user of Mathematica and have some questions about the simplifications of calculated expressions. I am unable to attach an image of the session, but my Mathematica commands are:

Element[{x,y,z},Reals] 
Element[{x0,y0,z0},Reals]
rhatV={x-x0,y-y0,z-z0}
rhat=Norm[rhatV]

In the expression for rhat, I am unable to get rid of the Abs functions, despite the Reals declarations.

phi=1/rhat
D[phi,x]

In the evaluated derivative is there a way to have x-x0 in the numerator recognized as rhatV[[1]] and the denominator as rhat^3, such that it can be used in additional operations?

$\endgroup$
2
  • $\begingroup$ Look up Assuming[]... $\endgroup$ Nov 21, 2012 at 15:59
  • $\begingroup$ The documentation included with Mathematica includes two tutorials you should read: Using Assumptions and Simplifying with Assumptions. $\endgroup$
    – m_goldberg
    Nov 21, 2012 at 22:31

2 Answers 2

7
$\begingroup$

The formulation of the assumptions are one problem, and the fact that you're not using them is another:

$Assumptions = {Element[{x, y, z}, Reals],
   Element[{x0, y0, z0}, Reals]
   };

rhatV = {x - x0, y - y0, z - z0};

rhat = Simplify[Norm[rhatV]];

phi = 1/rhat;

D[phi, x]

$-\frac{x-\text{x0}}{\left((x-\text{x0})^2+(y-\text{y0 })^2+(z-\text{z0})^2\right)^{3/2}}$

Here I put the assumptions in a special variable $Assumptions, assuming (no pun intended) that you'll want to re-use them in further calculations. But to use them in the first place, you have to add Simplify or another command that specifically utilizes the Assumptions option.

$\endgroup$
2
  • $\begingroup$ Thanks, I thought that the declaration of the variables as Reals would be automatically incorporated in subsequent calculations, but I understand from your response that it should be formulated as Assumptions and have calculations specifically invoke the Assumptions. I hope there is a way to have substitutions made so that the numerator is recognized as the first element of the vector rhatV and the denominator as rhat^3. $\endgroup$ Nov 21, 2012 at 17:01
  • $\begingroup$ @user1031565 For the last part of the question, you may be better off using spherical coordinates. $\endgroup$
    – Jens
    Nov 21, 2012 at 19:23
9
$\begingroup$

Mathematica is a term rewriting system, variables need not to be declared as in compiled languages. For a general view I recommend reading this post by Leonid Shifrin. In general, symbolic variables are processed as complex if not assumed otherwise. To specify assumptions there are a few ways :

  • $Assumptions are recommended when you want to use global assumptions.
  • for local assumptions there is Assuming[ assum, expr] where expr can be a compound expression (see CompoundExpression, a shorthand - ;) :
Assuming[ assum, expr]    evaluates expr with assum appended to $Assumptions, so that assum
is included in the default assumptions used by functions such as Refine, Simplify, and
Integrate

Many functions as Simplify, Refine, and Integrate have options Assumptions that specifies default assumptions to be made about symbolic quantities.

Here are a few examples how to specify desired assumptions and compute a given expression :

D[ Simplify[ 1/ Norm @ rhatV, {x, y, z}  ∈ Reals && {x0, y0, z0}  ∈ Reals], x]   

and

D[ Simplify[ 1/EuclideanDistance[{x, y, z}, {x0, y0, z0}], 
             {x, y, z}  ∈ Reals && {x0, y0, z0}  ∈ Reals], x] 

and

Assuming[ {x, y, z}  ∈ Reals && {x0, y0, z0}  ∈ Reals, D[ 1/Simplify @ Norm @ rhatV, x] ]

all these expressions return :

enter image description here

$\endgroup$
1
  • $\begingroup$ Thanks to you and @Jens for clearing up my confusion on declarations. $\endgroup$ Nov 21, 2012 at 17:05

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.