wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes How do I handle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How do I handle "The Matrix" ?" Watch "How do I handle "The Matrix" ?" New topic
Author

How do I handle "The Matrix" ?

Kristian Andersson
Greenhorn

Joined: Apr 23, 2004
Posts: 7
I'm trying to learn more about how a matrix works. I tried to find it at the API specification. But a matrix is neither a class or method and thus I had a hard time finding anything of value or interest.
Therefore, I hope to get some answers when posting on this forum. I wonder, how do I call a method when I use a matrix as an argument? And is there any way I can use something similiar to a StringBuffer with a matrix?
Kristian Andersson, Sweden
Ellen Zhao
Ranch Hand

Joined: Sep 17, 2002
Posts: 581
how a matrix works? Depends on what you want to accomplish with your matrix. Matrix works in different ways when you do matrix addition or multiplication or....You'd better consult some textbooks on linear algebra, it's not difficult to understand.
In java everything is an object, you can make matrix an object too. You can write a big package of Matrix for sophisticated numerical computing or just a Matrix class to do simple tasks. If you want to use a matrix as an argument, you have to define a type Matrix, i.e. class Matrix{...}, first. Only after that can you pass the Matrix as an argument in the signature of a method in another class. Sure, there are various ways you can manipulate the strings in a matrix...can you specify your task a bit more clearly?

Regards,
Ellen
[ April 23, 2004: Message edited by: Ellen Zhao ]
Tobias Hess
Ranch Hand

Joined: Apr 06, 2004
Posts: 55
How do I handle "The Matrix" ?
You can't, the matrix handles you.
For simple matrix things you can use arrays. Look it up in your favorite textbook. More complex things can be done by creating a class, as Ellen mentioned before.
Tobias
sever oon
Ranch Hand

Joined: Feb 08, 2004
Posts: 268
Yea, as your previous respondents have already said, it totally depends on the problem domain you're trying to cover. If you want to do simple matrix operations, then just use 2D arrays (or n-D arrays for tensors...ooh).

...and so on. I must say, though, this approach sort of rubs me the wrong way because it seems more or less like a non-OO approach. Better to make a class called MatrixCalculator instead that allows running operations and can do validity checks and such, allowing you to get the result any time you wish:

Here's how you might use your newfound MatrixCalculator:

The above will print out:
[ 20 15 ]
[ 15 20 ]
sev
Kristian Andersson
Greenhorn

Joined: Apr 23, 2004
Posts: 7
Thanks for all the replies, but I believe that the last post is a bit more advanced than I can handle. To make matters more simple, all I want to know for now is how to loop through a matrix. I tried to write the following to loop through a matrix (with three String-arrays stored inside of it) named "matrix":

But it didn't work. I had three arrays stored inside of the matrix, and I could only print out the contents of the first array.
To put this shortly all I would like to know is how to go through the data stored inside of a matrix. The reason I am doing this is because of a task I was given from the college that I study at. It might seem as though I try to cheat my way through it - but the reason I made the post on this forum is because I couldn't find anything on the API-documentation, as a matrix is neither a class or method.
Thanks for all the help so far,
Kristian Andersson, Sweden
Eddie Vanda
Ranch Hand

Joined: Mar 18, 2003
Posts: 281

This is a very simple way to generate and display a matrix. I made it of strings because you mentioned setting up a few strings. However, you cannot do any maths with this matrix unless you convert each string into a number.
What is not obvious from this example that this matrix consists of an array of rows held in a single column array. I you like I could post a bit of code which generates the array in code which makes that more obvious.
Ed


The nice thing about Standards is that there are so many to choose from!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I handle "The Matrix" ?
 
Similar Threads
Matrix
"Non-static method cannot be referenced from a static context" ?
Learning Project 2
Buttons...
Texturing a matrix