# How to delete $n^{th}$ row and $n^{th}$ column of a matrix K in Petsc and restructure it?

I have a matrix K in Petsc. I want to delete the $$n^{th}$$ row and $$n^{th}$$ column of this matrix and restructure it. I am a beginner in Petsc. Can you suggest how to do it?

Example: I have matrix K of size 100 x 100. I want to remove the 10th row and 10th column so that the remaining restructured matrix is 99 x 99.

You don't do that for large and sparse matrices. It's an inefficient operation. Rather, you zero out the $$n$$th row and column and put a nonzero entry on the diagonal. Then you think about what operations that you wanted to do on the $$99\times 99$$ matrix need to look like on the modified $$100\times 100$$ matrix.
• Yes, if you delete a row and column and place a value of $a$ on the diagonal, you get one eigenvalue equal to $a$. In other words, if you are looking for the smallest eigenvalue, you want to choose $a$ to equal, for example, the magnitude of the largest diagonal entry in hopes that $a$ is then larger than the smallest eigenvalue. You generally want to ensure that $a$ is on the same order of magnitude as the other entries in the matrix to make sure the resulting matrix remains well-conditioned. – Wolfgang Bangerth Jun 3 at 16:33
• I do think that zeroing out rows and columns is much easier to implement than actually shrinking the size of the matrix to $99\times 99$. – Wolfgang Bangerth Jun 3 at 16:34