1

These equations set up an operation I'm trying to do to calculate the Christoffel Symbol:

X[r_, theta_] := r*Cos[theta]; 
Y[r_, theta_] := r*Sin[theta]; 
R[x_, y_] := Sqrt[x^2 + y^2]; 
Theta[x_, y_] := ArcTan[x, y];

So I now perform the calculation which is equivalent to:$$\Gamma^{r}_{\theta \theta}=\frac{\partial^2x}{\partial^2\theta}\frac{\partial r}{\partial x}+\frac{\partial^2y}{\partial^2\theta}\frac{\partial r}{\partial y}$$ My implementation is:

Simplify[D[D[X[r, theta], theta], theta]*D[R[x, y], x] + D[D[Y[r, theta], theta], theta]*D[R[x, y], y] /. {y -> Y[r, theta], x -> X[r, theta]}]

Which works, but gives me the answer:$$-\sqrt{r^2}$$ It appears to my untrained eyes that this is equivalent to $-r$ (which is the real answer I'm after). How do I force mathematica to reduce this? Am I missing something?

Quark Soup
  • 1,610
  • 9
  • 14

1 Answers1

3

By default, Mathematica does not simplify Sqrt[r^2] to r due to the fact that r could be negative, or positive, and r^2 will yield the same result, however the Sqrt function is defined to only result in in the positive value of r.

If you assume that r is always positive, then -Sqrt[r^2] can be simplified to -r

Yusuf Bashi
  • 164
  • 7
  • Sqrt[r^2] is just another way to write Abs[r] (absolute value) – Yusuf Bashi Dec 21 '19 at 01:04
  • $r$ is the radius and can't be negative (radius can't be negative, can it?). Can I force this to reduce by setting assumption telling the simplification that $r$ can only be positive? If so, would you please suggest how to do this (I'm still pretty new to Mathematica). – Quark Soup Dec 21 '19 at 01:06
  • 1
    Yes, you can use Assumptions-> . Here is documentation: https://reference.wolfram.com/language/ref/Assumptions.html In your case, you can use the following code to simplify, which will output -r Code: Simplify[D[D[X[r, theta], theta], theta]*D[R[x, y], x] + D[D[Y[r, theta], theta], theta]*D[R[x, y], y] /. {y -> Y[r, theta], x -> X[r, theta]}, Assumptions->r>0] – Yusuf Bashi Dec 21 '19 at 01:13