# Thread: Minor of a matrix

1. ## Minor of a matrix

I have a 4x4 matrix that I need to find the minor of.

4 5 6 2
3 4 5 5
7 4 3 3
5 7 6 8

The minor is basically the resultant matrix that you get when you remove the row/column that [i,j] is in. So for instance, if I had a Matrix(A), and I needed the minor of A[2,3], I would be removing (from the above) I would end up with the following matrix:

4 5 6
3 4 5
5 7 6

Any ideas on how I could get that result? Preferably something where I could pass in the 2d array representing the matrix, and the i,j position that I wanted to eliminate.

2. Why do you need to find the minor of a matrix? Do you want to find the determinant of a matrix? There are better ways ...

kind regards,

Jos

3. yes, the assignment is to recursively find the determinant of a matrix, preferably using the minor. so its something like

public double FindDeterminant(double[][] inputMatrix){
double determinant = 0;
//logic

return determinant;
}

4. Originally Posted by sehudson
yes, the assignment is to recursively find the determinant of a matrix, preferably using the minor. so its something like

public double FindDeterminant(double[][] inputMatrix){
double determinant = 0;
//logic

return determinant;
}
If you really have to use the minors of a matrix I'd use 'views' on the matrix; here's how: first define an interface:

Java Code:
```interface MatrixView {
double get(int i, int j);
int dim();
}```
This doesn't say much but here's a RawMatrixView that offers a 1 to 1 view of a raw matrix:

Java Code:
```class RawMatrixView implements MatrixView {
private double[][] mat;

public RawMatrixView(double[][] mat) {
this.mat= mat;
}

public double get(int i, int j) {
return mat[i][j];
}

public int dim() {
return mat.length;
}
}```
This doesn't say much either but given this first class we can build a MinorMatrixView:

Java Code:
```class MinorMatrixView implements MatrixView {
MatrixView mv;
int r, c;

MinorMatrixView(MatrixView mv, int r, int c) {
this.mv= mv;
this.r= r;
this.c= c;
}

public double get(int i, int j) {
if (i >= r) i++;
if (j >= c) j++;
return mv.get(i, j);
}

public int dim() {
return mv.dim()-1;
}
}```
As you can see from this class if a row or column element is refered it simply returns the element in the next row or column. And, more important all MatrixView objects can be wrapped by others allowing for a recursive approach (needed by your determinant finding method).

Here's a small class that tests the entire thing:

Java Code:
```public class T {
public static void main(String[] args) {
double[][] mat= {
{ 1, 2, 3, 4 },
{ 2, 3, 4, 5 },
{ 3, 4, 5, 6 },
{ 4, 5, 6, 7 }
};

MatrixView rmv= new RawMatrixView(mat);
MinorMatrixView mmv= new MinorMatrixView(rmv, 1, 2);

for (int i= 0; i < mmv.dim(); i++) {
for (int j= 0; j < mmv.dim(); j++)
System.out.print(mmv.get(i, j)+" ");
System.out.println();
}
}
}```
This class builds a minor (ignore row 1, column 2) of a raw matrix. I think you can take it from here.

kind regards,

Jos
Last edited by JosAH; 02-22-2011 at 12:20 PM. Reason: fixed a bit of code in the MinorMatrixView class; sorry about the mistake ...

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•