9
$\begingroup$

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 $$

$\endgroup$
8
  • 2
    $\begingroup$ You can do no harm by trying. $\endgroup$ Oct 28, 2013 at 20:06
  • $\begingroup$ 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. $\endgroup$
    – pitchounet
    Oct 28, 2013 at 20:13
  • 1
    $\begingroup$ 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. $\endgroup$
    – Artes
    Oct 28, 2013 at 20:24
  • $\begingroup$ 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 ? $\endgroup$
    – pitchounet
    Oct 28, 2013 at 21:06
  • $\begingroup$ 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. $\endgroup$
    – Artes
    Oct 28, 2013 at 21:45

1 Answer 1

16
+50
$\begingroup$

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
$\endgroup$
5
  • $\begingroup$ 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 ? $\endgroup$
    – pitchounet
    Oct 31, 2013 at 17:19
  • $\begingroup$ @jibounet Well, does it make any sense to transpose a vector? $\endgroup$
    – Szabolcs
    Oct 31, 2013 at 17:20
  • $\begingroup$ 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})$. $\endgroup$
    – pitchounet
    Oct 31, 2013 at 17:30
  • 1
    $\begingroup$ @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. $\endgroup$
    – Szabolcs
    Oct 31, 2013 at 17:31
  • $\begingroup$ Alright. I understand. $\endgroup$
    – pitchounet
    Oct 31, 2013 at 17:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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