Results 1 to 2 of 2
Thread: Use a 'nested class' here?
- 01-24-2011, 12:57 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 2
- Rep Power
- 0
Use a 'nested class' here?
Hi,
I have written a class called 'Matrix', which as the name implies, is an implementation of the mathematical concept of a matrix (this being a 2 dimensional array of numbers).
There is something called an 'LU decomposition' in matrix theory, that takes a matrix, and 'decomposes' it in to two other matrices, called the 'L' and the 'U' matrices.
Now, as one of the methods for the 'Matrix' class, I have written one that performs an 'LU decomposition'. Clearly, this has to return two items - the L and the U matrices.
As Java only allows methods to return one return type, then I've resorted to tagging the matrices to a List and then to return the list. But, I've thought of a better way, and that is to create a 'nested class' called 'LUdecomposition' within the Matrix class, and then to simply only have a constructor within that class, and then to have the Lmatrix and Umatrix as arguments.
The luDecomposition method would then simply return an instance of this nested class as a return type.
Would you say this is a good way to approach this? Any better suggestions?
- 01-24-2011, 01:15 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
Why not make the LUDecomposition class a separate class? There is no need to make it a nested class of the Matrix class. Also note that all elements on the diagonal of the L matrix are 1 (one) so there's no need to store them explicitly. That way you can pack both the L and U matrixes in one square Matrix.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
Nested Loops
By candygirl198827 in forum New To JavaReplies: 38Last Post: 12-01-2010, 06:03 AM -
Nested List class for Simulation Queue
By Cheddz in forum Advanced JavaReplies: 2Last Post: 02-19-2010, 01:19 AM -
can some one help me with nested loop?
By keycoffee in forum New To JavaReplies: 10Last Post: 01-25-2010, 02:49 AM -
Nested Classes
By new.guy in forum New To JavaReplies: 13Last Post: 09-07-2008, 04:44 AM -
Nested For Loop
By yuchuang in forum New To JavaReplies: 1Last Post: 07-08-2007, 01:11 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks