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[1] -- can be interpreted as a matrix
since, say, taking the dot product of a 3 by 3 structure of integers
makes sense (see In[4]). However, mat is still a regular expression and
Mathematica can works on it element by element (see In[2] and In[3]).
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[4] and In[5]).
Finally, the article "Functions of Matrices" [1] may be of interest.
In[1]:=
mat = {{0, 0, 0}, {1, -1, -1}, {-1, 1, 1}};
In[2]:=
mat^2
Out[2]=
{{0, 0, 0}, {1, 1, 1}, {1, 1, 1}}
In[3]:=
mat*mat
Out[3]=
{{0, 0, 0}, {1, 1, 1}, {1, 1, 1}}
In[4]:=
mat . mat
Out[4]=
{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}
In[5]:=
MatrixPower[mat, 2]
Out[5]=
{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}
HTH,
Jean-Marc
[1]
http://documents.wolfram.com/mathematica/Built-inFunctions/AdvancedDocumentation/LinearAlgebra/LinearAlgebraInMathematica/MatrixComputations/AdvancedDocumentationLinearAlgebra3.5.html