15
$\begingroup$

How can I do vector calculations without telling Mathematica the vector entries?

I have very many arbitrary linear combinations in $\mathbb{R}^3$ which I want to perform some general calculations on (scalar and vector products) and want to use Mathematica to do this (especially for simplifying stuff like very long equations with scalar prodcuts of vector products).

So, I don't want to write for all my vectors stuff like v1={a1,b1,c1} ... vN={aN,bN,cN} and so on, but just want to say v1 ... vN are vectors.

How is this possible?

$\endgroup$
2
  • $\begingroup$ You can start here. $\endgroup$
    – Szabolcs
    May 24, 2013 at 19:31
  • $\begingroup$ You can always generate stuff like v1={a1,b1,c1} by defining a function, if you don't want to specify this manually. $\endgroup$
    – mmal
    May 24, 2013 at 19:34

2 Answers 2

21
$\begingroup$

Assuming that we have three-dimensional real vectors :

$Assumptions = (u | v | w) ∈ Vectors[3, Reals];

we can use e.g. various tensor functions (new in ver. 9) e.g. TensorReduce to reduce (simplify) a tensor expression, e.g.

TensorReduce[ v.v + w.w - (v + w).(v + w) ]
TensorReduce[u \[Cross] (v \[Cross] w) ]
-2 v.w
-w u.v + v u.w

We can perform more interesting reductions, let's show e.g. the Jacobi identity:

TensorReduce[ u \[Cross] (v \[Cross] w) + v \[Cross] (w \[Cross] u) + 
              w \[Cross] (u \[Cross] v) ]
0

or write it in a traditional form:

Defer[   u \[Cross] (v \[Cross] w) + v \[Cross] (w \[Cross] u)
       + w \[Cross] (u \[Cross] v)] == 
TensorReduce[   u \[Cross] (v \[Cross] w) + v \[Cross] (w \[Cross] u)
              + w \[Cross] (u \[Cross] v) ] // TraditionalForm

enter image description here

Another common identity

TensorExpand[ (u \[Cross] v) \[Cross] (u \[Cross] w) ]
TensorExpand[ (u \[Cross] v).(u \[Cross] v) ]
u u \[Cross] v . w
-(u.v)^2 + u.u  v.v

Take a look at new differential operators:

Curl[ Curl[ f[x, y, z], {x, y, z}], {x, y, z}] == Laplacian[ f[x, y, z], {x, y, z}]
True
$\endgroup$
1
  • $\begingroup$ {1, 2, 3} \[Element] Vectors[3, Reals] evaluates to True, yet v + {1, 2, 3} evaluates to {1+v,2+v,3+v}. Any suggestions on how to properly suppress this Listable attribute of Plus where it isn't appropriate? $\endgroup$
    – RRas
    Aug 8, 2019 at 16:23
6
$\begingroup$

@Szabolcs is right, use Symbolic Tensors. But in that link it may be a bit confusing to find what you want. There are good examples on 3D vector operations. Read:

For example, proving an identity:

a\[Cross](b\[Cross](c\[Cross]d)) == b a.(c\[Cross]d) - (a.b) c\[Cross]d // TensorExpand

True

Or expanding something very long:

((a\[Cross]b).c)^4 // TensorExpand

(a.c)^4 (b.b)^2 - 4 a.b (a.c)^3 b.b b.c + 4 (a.b)^2 (a.c)^2 (b.c)^2 + 2 a.a (a.c)^2 b.b (b.c)^2 - 4 a.a a.b a.c (b.c)^3 + (a.a)^2 (b.c)^4 + 2 (a.b)^2 (a.c)^2 b.b c.c - 2 a.a (a.c)^2 (b.b)^2 c.c - 4 (a.b)^3 a.c b.c c.c + 4 a.a a.b a.c b.b b.c c.c + 2 a.a (a.b)^2 (b.c)^2 c.c - 2 (a.a)^2 b.b (b.c)^2 c.c + (a.b)^4 (c.c)^2 - 2 a.a (a.b)^2 b.b (c.c)^2 + (a.a)^2 (b.b)^2 (c.c)^2

$\endgroup$
1
  • $\begingroup$ How can I add Real prefactors to the vectors with TensorExpand? $\endgroup$
    – Foo Bar
    May 24, 2013 at 19:44

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.