Re: Manipulating a matrix
- To: mathgroup at smc.vnet.net
- Subject: [mg59246] Re: Manipulating a matrix
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Wed, 3 Aug 2005 01:19:50 -0400 (EDT)
- Organization: The Open University, Milton Keynes, U.K.
- References: <dcmuig$glg$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Ramier wrote: > Hello everyone, > > I think that my question is rather simple and maybe I ought to go > deeper into Mathematica book: > I have a n x n matrix and I'd like to remove the first line and the > first column in order to get the (n-1)x(n-1) matrix with the entries > remaining. Is there a simple way to do that ? > > Perhaps my question is really simple or idiot but I've never used > Mathematica before. > > Thanks a lot, > > Wissam > Hi, You can use the *Drop* function as in the following examples. Say we have a 3x3 matrix called "mat" In[1]:= mat = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}} Out[1]= {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}} In the Mathematica front-end we can see the matrix as a matrix and not a list of list: In[2]:= MatrixForm[mat] Now we get rid of the first element of the list, that is the first line of the matrix: In[3]:= m = Drop[mat, 1] Out[3]= {{4, 5, 6}, {7, 8, 9}} In[4]:= MatrixForm[m] To get discard the first column we transpose the matrix, drop the first line of the transposed matrix, and transpose again to get the original order of lines and columns: In[5]:= m = Transpose[Drop[Transpose[m], 1]] Out[5]= {{5, 6}, {8, 9}} In[6]:= MatrixForm[m] Of course, you can do all these operations in only one-step as follows: In[7]:= m = Transpose[Drop[Transpose[Drop[mat, 1]], 1]] Out[7]= {{5, 6}, {8, 9}} Best regards, /J.M.