Win a copy of Penetration Testing Basics this week in the Security forum!

# How do I handle "The Matrix" ?

Greenhorn
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?

Ellen Zhao
Ranch Hand
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
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
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

Greenhorn
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,