       Re: mathematica newbie question

• To: mathgroup at smc.vnet.net
• Subject: [mg66912] Re: mathematica newbie question
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Sat, 3 Jun 2006 03:26:19 -0400 (EDT)
• Organization: The Open University, Milton Keynes, UK
• References: <e5osv8\$i51\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Jeremy Watts wrote:
> Hi,
>
> Just trying to get to grips with Mathematica and matrices.  Why is it when I
> enter :-
> {0, 0, 0}, {1, -1, -1}, {-1, 1, 1}}^2
>
> then Mathematica returns :-
>
> {{0, 0, 0}, {1, 1, 1}, {1, 1, 1}}
>
> and not {{0,0,0},{0,0,0},{0,0,0}} (the actual square of the matrix) as I'd
> have expected?
>
> Is it treating what I entered as separate vectors or something, and not  an
> actual matrix?

Hi Jeremy,

Mathematica knows nothing about "matrices" per se. Well, this statement
is slightly extreme; but the fact is that, to Mathematica, a list of
lists is first a list of lists that can contains lists of different
lengths, each of them holding elements of different types. For instance,
the following list is a valid construct in Mathematica

{{a,b,c},{"Some string",{1,2,{3,4},index}},{Sin,Cos}}

Of course, this expression cannot be interpreted as a matrix.

On the other hand, your original expression -- called "mat" in the
remaining of this post, see In -- can be interpreted as a matrix
since, say, taking the dot product of a 3 by 3 structure of integers
makes sense (see In). However, mat is still a regular expression and
Mathematica can works on it element by element (see In and In).

Therefore, to get raise a matrix to a power, either use repeatedly the
dot product or use special built-in functions such as MatrixExp or
MatrixPower (see In and In).

Finally, the article "Functions of Matrices"  may be of interest.

In:=
mat = {{0, 0, 0}, {1, -1, -1}, {-1, 1, 1}};

In:=
mat^2

Out=
{{0, 0, 0}, {1, 1, 1}, {1, 1, 1}}

In:=
mat*mat

Out=
{{0, 0, 0}, {1, 1, 1}, {1, 1, 1}}

In:=
mat . mat

Out=
{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}

In:=
MatrixPower[mat, 2]

Out=
{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}

HTH,
Jean-Marc