5
$\begingroup$

I want to get the Norm of a vector which involves sines and cosines (So I really need to replace it by the Pythagorean theorem). Since I know that all my results are going to be real and positive I don't care about the Abs before squaring the terms.

How can I get $$ \sqrt{ r_x ^ 2 + r_y ^ 2 + r_z ^ 2 }$$

Instead of: $$ \sqrt{ |r_x| ^ 2 + |r_y| ^ 2 + |r_z| ^ 2 }$$

$\endgroup$
4
  • 5
    $\begingroup$ Sqrt[vec.vec] where vec is your vector. . in Mathematica is the dot product. $\endgroup$
    – C. E.
    Commented Apr 16, 2017 at 19:34
  • $\begingroup$ @C.E. Thanks! I was doing it with loops but I didnt expect such elegant solution! Could you add it as an answer please? $\endgroup$ Commented Apr 16, 2017 at 19:41
  • 1
    $\begingroup$ Norm[vec] // ComplexExpand $\endgroup$
    – Bob Hanlon
    Commented Apr 16, 2017 at 21:54
  • $\begingroup$ As @BobHanlon says (and I thank you) ComplexExpand is more generalized solution to annoying complex numbers problem. $\endgroup$
    – Chameleon
    Commented May 24, 2020 at 16:10

1 Answer 1

8
$\begingroup$

That expression is the square root of the dot product of the vector by itself:

Sqrt[vec.vec]

where vec is your vector.

$\endgroup$

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