• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

How do I handle "The Matrix" ?

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 581
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
If you try to please everybody, your progress is limited by the noisiest fool. And this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic