Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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
1  
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
1  
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
show 3 more comments

1 Answer 1

up vote 12 down vote accepted
+50

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
add comment

Your Answer

 
discard

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.