Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to do symbolic matrix manipulations

1,279 views
Skip to first unread message

Peng Yu

unread,
Sep 26, 2008, 6:05:10 PM9/26/08
to
Hi,

Suppose I have matrices a and b, which does not have any value yet.

If I write b * a, mathematica would give me "a b". I'm wondering how to make
it know that a and b are matrices, so that it would give me "b a" rather
than "a b".

Thanks,
Peng

Jose Luis Gomez

unread,
Sep 27, 2008, 6:46:47 AM9/27/08
to
In Mathematica the asterisk is used for commutative multiplication, for the
noncommutative matrix multiplication you must use a dot: a.b

See this link:
http://reference.wolfram.com/mathematica/ref/Dot.html

Be sure to check also MatrixPower, or you will also have problems with
powers of matrices:
http://reference.wolfram.com/mathematica/ref/MatrixPower.html

Hope that helps

Jose
Mexico

-----Mensaje original-----
De: Peng Yu [mailto:peng...@gmail.com]
Enviado el: Viernes, 26 de Septiembre de 2008 05:24
Para: math...@smc.vnet.net
Asunto: How to do symbolic matrix manipulations

Bill Rowe

unread,
Sep 27, 2008, 6:47:54 AM9/27/08
to
On 9/26/08 at 6:23 AM, peng...@gmail.com (Peng Yu) wrote:

>Suppose I have matrices a and b, which does not have any value yet.

>If I write b * a, mathematica would give me "a b". I'm wondering how
>to make it know that a and b are matrices, so that it would give me
>"b a" rather than "a b".

The key here is to realize b*a will always commute including
when both a,b are matrices since this does an element by element
multiplication not a matrix multiplication. Simply do matrix
multiplication using Dot and there is no problem. That is

In[1]:= b.a

Out[1]= b.a

Jean-Marc Gulliet

unread,
Sep 27, 2008, 6:48:29 AM9/27/08
to
Peng Yu wrote:

> Suppose I have matrices a and b, which does not have any value yet.

Beware that Mathematica is not a strongly-type language and things like
vector or matrix do not exist per se. A vector can be represented by a
one dimensional list holding appropriate element, a matrix by a two
dimensional list; but a generic type vector or matrix does not exist
natively.

> If I write b * a, mathematica would give me "a b". I'm wondering how to make
> it know that a and b are matrices, so that it would give me "b a" rather
> than "a b".

You could use the non-commutative multiplication operator **.

In[213]:= b ** a

Out[213]= b ** a

If you are going to do extensive symbolic manipulation withe generic
objects, you may want to define your own matrix type (say expression
with head matrix, i.g. something like matrix[a]) and
associate/(re)define properties and operator.

Regards,
-- Jean-Marc

Peter Breitfeld

unread,
Sep 27, 2008, 6:49:37 AM9/27/08
to
Peng Yu schrieb:

a*b gives the matrix (a_ij * b_ij) which is the same as (b_ij*a_ij),
so a*b=b*a.

I think you want to do matrix multiplication, which ist done by a.b
or Dot[a,b]. If you enter b.a the result will be b.a not a.b

Gruss Peter
--
==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de

Adriano Pascoletti

unread,
Sep 27, 2008, 6:46:36 AM9/27/08
to
0 new messages