16
$\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
    Commented 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
    Commented May 24, 2013 at 19:34

3 Answers 3

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
    Commented 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
    Commented May 24, 2013 at 19:44
5
$\begingroup$

Version 14.1 introduced a new approach for calculations with symbolic vectors and matrices by using VectorSymbol and MatrixSymbol. In this way, you do not work with Assumptions anymore, but directly define your symbolic vectors and arrays.

Let me reproduce the examples from Artes' answer and add a few more.

First, you define your symbols:

u = VectorSymbol["u", 3, Reals];
v = VectorSymbol["v", 3, Reals];
w = VectorSymbol["w", 3, Reals];

Note that the first argument simply denotes the name that will be displayed – it does not need to match the symbol you are associating it with.

TensorReduce[v . v + w . w - (v + w) . (v + w)]
TensorReduce[u\[Cross](v\[Cross]w)]
TensorReduce[u\[Cross](v\[Cross]w) + v\[Cross](w\[Cross]u) + w\[Cross](u\[Cross]v)]
TensorExpand[(u\[Cross]v)\[Cross](u\[Cross]w)]
TensorExpand[(u\[Cross]v) . (u\[Cross]v)]
Reduce[v . {1, 2, 3} == 1]
D[Norm[v], {v, 3}]
D[v[t], t]
D[Norm[v[t]], {t, 2}]
v + {1, 2, 3}

enter image description here

Note the key differences:

  1. Vectors are typeset with an arrow over them.
  2. The third output is not a scalar 0, but a symbolic zero vector with dimension 3, represented with SymbolicZerosArray.
  3. There are several other symbolic objects, such as SymbolicIdentityArray, SymbolicOnesArray and SymbolicDeltaProductArray.
  4. VectorSymbol is NonThreadable, which means that listable functions will not combine it in the result (compare the last result with a + {1, 2, 3}).

As you can see from the results above, the dimensions of vectors need not be numeric, you can perfectly well define a vector in $n$ dimensions:

r = VectorSymbol["r", n, Reals];
D[r, r]
(* SymbolicIdentityArray[{n}] *)
$\endgroup$

Your Answer

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

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