Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to know how I can ask Mathematica to expand (and simplify) such an expression :

$$ (\alpha A + \beta B)^\top (\alpha A + \beta B) $$

where $\alpha,\beta$ are two real numbers and $A,B$ are vectors in $\mathbb{R}^{n}$. $A^\top$ denotes the transpose of $A$. I assume I must tell Mathematica that $A$ and $B$ are vectors. Here is what I have tried :

$Assumptions = (A | B) [Element] Vectors[n];
    $Assumptions = (a | b) [Element] Reals;
TensorExpand[ Transpose[a*A + b*B].(a*A + b*B) ]

and the output is :

a A.Transpose[a A + b B, {2, 1}] + b B.Transpose[a A + b B, {2, 1}]

Which is not what I expected since I would like the output to be :

$$ \alpha^{2} A^\top A + 2 \alpha \beta A^\top B + \beta^{2} B^\top B $$

share|improve this question
You can do no harm by trying. – b.gatessucks Oct 28 '13 at 20:06
I would if I had Mathematica on the computer I'm currently using but I don't. I can't try it right now but I will later. – jibounet Oct 28 '13 at 20:13
This is closely related: How can I get Mathematica to recognize equality of symbolic matrix expressions?. In fact, following the answer you should resolve your prolem, i.e. use TensorReduce instead of FullSimplify. – Artes Oct 28 '13 at 20:24
I have tried : $Assumptions = (A | B) [Element] Matrices[{n, 1}]; TensorExpand[ Transpose[A + B].(A + B) ] But the output I get is not Transpose[A].A + 2Transpose[A].B + Transpose[B].B What did I do wrong ? – jibounet Oct 28 '13 at 21:06
You can use Vectors[n]. In your original question you have ( a*A + b*B)]*( a*A + b*B), instead of * use . i.e. Dot or you can use TensorProduct. – Artes Oct 28 '13 at 21:45
up vote 14 down vote accepted

Since you're working with vectors, just let Mathematica know that these are vectors. Some other systems (MATLAB and its relatives in particular) have the limitation that they can only work with matrices, forcing you to distinguish between row vector and column vectors and keep transposing. This is not necessary nor convenient in Mathematica.

In[1]:= $Assumptions = a ∈ Vectors[n, Reals] && b ∈ Vectors[n, Reals]
Out[1]= a ∈ Vectors[n, Reals] && b ∈ Vectors[n, Reals]

In[2]:= (α a + β b).(α a + β b) // TensorExpand
Out[2]= α^2 a.a + 2 α β a.b + β^2 b.b
share|improve this answer
Thank you for your answer! It seems to work just fine in your example. However, would it still work if I had Transpose[] to your example ? – jibounet Oct 31 '13 at 17:19
@jibounet Well, does it make any sense to transpose a vector? – Szabolcs Oct 31 '13 at 17:20
I think it does. A real vector $X$ belongs to $\mathrm{Mat}_{n,1}(\mathbb{R})$. We can define its transpose to be the matrix of the linear form $L_{X} \, : \, Y \in \mathbb{R}^{n} \, \longmapsto \, \left\langle X,Y \right\rangle$, which is an element of $\mathrm{Mat}_{1,n}(\mathbb{R})$. – jibounet Oct 31 '13 at 17:30
@jibounet For Mathematica a "vector" is a 1-dimensional tensor. What people call a "row vector" is a really a matrix, i.e. a 2-dimensional tensor. It's more difficult to reason about those and figure out such things that $AB^T=BA^T$ only if both A and B are 1 by $n$ matrices, but not otherwise. In Mathematica it does not make sense to transpose a vector because it's a one-dimensional structure. – Szabolcs Oct 31 '13 at 17:31
Alright. I understand. – jibounet Oct 31 '13 at 17:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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