Results 1 to 4 of 4
Thread: Minor of a matrix
 02212011, 07:39 PM #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.
 02212011, 08:03 PM #2
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,389
 Blog Entries
 7
 Rep Power
 25
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,
JosThe only person who got everything done by Friday was Robinson Crusoe.
 02212011, 08:43 PM #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;
}
 02212011, 09:12 PM #4
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,389
 Blog Entries
 7
 Rep Power
 25
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(); }
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; } }
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; } }
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(); } } }
kind regards,
JosLast edited by JosAH; 02222011 at 12:20 PM. Reason: fixed a bit of code in the MinorMatrixView class; sorry about the mistake ...
The only person who got everything done by Friday was Robinson Crusoe.
Similar Threads

Help with dox matrix printer
By Albert in forum Advanced JavaReplies: 7Last Post: 09062011, 08:50 AM 
reading Matrix
By metrokid in forum New To JavaReplies: 1Last Post: 12042010, 01:48 PM 
Matrix class
By maz22 in forum New To JavaReplies: 5Last Post: 10152010, 06:53 AM 
help in matrix
By Engineer in forum New To JavaReplies: 7Last Post: 10062010, 01:26 PM 
Help with matrix
By susan in forum New To JavaReplies: 1Last Post: 08072007, 04:37 AM
Bookmarks