Ask Your Question
2

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

asked 2017-07-18 06:58:26 +0100

Deepak Sarma gravatar image

updated 2017-07-19 06:55:26 +0100

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
1

answered 2017-07-19 12:12:48 +0100

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 12:46:32 +0100 )edit
2

answered 2017-07-18 09:15:30 +0100

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 10:12:06 +0100 )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 11:30:22 +0100 )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 15:30:36 +0100 )edit

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

ndomes gravatar imagendomes ( 2017-07-18 17:55:22 +0100 )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-19 06:42:35 +0100 )edit
0

answered 2017-07-19 06:53:57 +0100

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-18 06:58:26 +0100

Seen: 8,798 times

Last updated: Jul 19 '17