Ask Your Question
1

Submatrix of a given matrix by deleting some rows and columns(For my case 2 rows and columns).

asked 2017-07-17 23:58:26 -0500

Deepak Sarma gravatar image

updated 2017-07-18 23:55:26 -0500

I have a matrix A of order $n\times n$. Now I need another matrix B whose (i,j)th entry is $det A(i,j)$, where $det A(i,j)$ denote the determinant of the sub matrix of A formed by deleting $i^{th}$ and $j^{th}$ rows and columns. I'm unable to generate the submatrices $A(i,j)$ for every element at a time.

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted
0

answered 2017-07-19 05:12:48 -0500

dan_fulea gravatar image

Let us fix a matrix $A$, so that the answer can be recovered every time. Since big coefficients should not occur on such a post, let us work over F = GF(5) first. We start with the matrix:

F = GF(5) A = matrix( F, 5, 5, [ 1 + k^2 + n^3 for k in F for n in F ] )

This is:

sage: A
[1 2 0 0 2]
[2 3 1 1 3]
[0 1 4 4 1]
[0 1 4 4 1]
[2 3 1 1 3]

Now, if the (pythonically numbered) rows $1,2$, and the columns $0,4$ have to be deleted, we have to extract (complementarily) the rows $0,3,4$, and the columns $1,2,3$. This is done for instance via:

sage: A[ [0,3,4] , [1,2,3] ] 
[2 0 0]
[1 4 4]
[3 1 1]

For our purposes, it is better to use the form:

R = range( 5 )
A[ [ k for k in R if k not in [1,2] ] ,
   [ k for k in R if k not in [0,4] ] ]

This is the same.

And now the answer to your question:

R = range( 5 )
S = set( R )
F = GF(5)
A = matrix( F, 5, 5, [ 1+k^2+n^3 for k in F for n in F ] )

B = matrix( F,
            5, 5,
            [ A[ list( S.difference( {j,k}) ) ,
                 list( S.difference( {j,k}) ) ].det()
              for j in R
              for k in R ] )

This is:

sage: B
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
edit flag offensive delete link more

Comments

Thank you.

Deepak Sarma gravatar imageDeepak Sarma ( 2017-07-19 05:46:32 -0500 )edit
2

answered 2017-07-18 02:15:30 -0500

You can create lists of rows and columns and use them to cut out a submatrix. E.g.

 sage: M=matrix([[1,2,3,4],[3,4,5,6],[6,7,8,9]])
 sage: M[[0,2],[0,2]]
 [1 3]
 [6 8]
edit flag offensive delete link more

Comments

For large matrix it is not that easy to construct each submatrix one by one. I need $n^2+n$ submatrices for a matrix of order n. I'm looking for a general rule or a program.

Deepak Sarma gravatar imageDeepak Sarma ( 2017-07-18 03:12:06 -0500 )edit

Well, but this is a straightforward Python loop to write. In the loop, create two lists, say, ro, co, using range(), remove i-th (resp. j-th) elements from it, call A[ro,co].det()/A[ro,ro].det() to compute the corr. determinant ratio, store it in B.

Dima gravatar imageDima ( 2017-07-18 04:30:22 -0500 )edit

Sorry, I could not get your point clearly. Can you please explain it with an example? Consider a random matrix of order 10 and from it find the submatrix by deleting 2nd and 7th rows and columns.

Deepak Sarma gravatar imageDeepak Sarma ( 2017-07-18 08:30:36 -0500 )edit

A live example with nested for loops: http://sagecell.sagemath.org/?q=dzgfjy

ndomes gravatar imagendomes ( 2017-07-18 10:55:22 -0500 )edit

Thank you. But the following one simply serves that purpose.

N = random_matrix(ZZ, 10,10) M=N.delete_rows([2,7]) P=M.delete_columns([2,7]). show(N) show(P)

My problem is that I'm unable to generate all such submatrix at a time. What I want is to replace each element of the given matrix by the determinant of such submatrix of that particular element.

Deepak Sarma gravatar imageDeepak Sarma ( 2017-07-18 23:42:35 -0500 )edit
0

answered 2017-07-18 23:53:57 -0500

Deepak Sarma gravatar image

I can find the submatrix for a particular element in the following way.

N = random_matrix(ZZ, 10,10) M=N.delete_rows([2,7]) P=M.delete_columns([2,7]) show(N) show(P)

My problem is that I'm unable to generate all such submatrix at a time. What I want is to replace each element of the given matrix by the determinant of such submatrix of that particular element. What I tried is the following one. But it shows some error.

L = random_matrix(ZZ, 10,10) R=matrix(QQ, 10) for i in range(10): for j in range(10): if i!=j: B(i,j)=L.delete_rows([i,j]) B(i,j)=B(i,j).delete_columns([i,j]) R[i,j]=B(i,j).det() show(R)

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2017-07-17 23:58:26 -0500

Seen: 89 times

Last updated: Jul 19