Results 1 to 4 of 4
Thread: Minor of a matrix
- 02-21-2011, 06: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.
- 02-21-2011, 07:03 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-21-2011, 07: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;
}
- 02-21-2011, 08:12 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
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:
This doesn't say much but here's a RawMatrixView that offers a 1 to 1 view of a raw matrix:Java Code:interface MatrixView { double get(int i, int j); int dim(); }
This doesn't say much either but given this first class we can build a MinorMatrixView: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; } }
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).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:
This class builds a minor (ignore row 1, column 2) of a raw matrix. I think you can take it from here.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; 02-22-2011 at 11:20 AM. Reason: fixed a bit of code in the MinorMatrixView class; sorry about the mistake ...
When people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
Help with dox matrix printer
By Albert in forum Advanced JavaReplies: 7Last Post: 09-06-2011, 08:50 AM -
reading Matrix
By metrokid in forum New To JavaReplies: 1Last Post: 12-04-2010, 12:48 PM -
Matrix class
By maz22 in forum New To JavaReplies: 5Last Post: 10-15-2010, 06:53 AM -
help in matrix
By Engineer in forum New To JavaReplies: 7Last Post: 10-06-2010, 01:26 PM -
Help with matrix
By susan in forum New To JavaReplies: 1Last Post: 08-07-2007, 04:37 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks