Multiply and Add matrices with 2d array WITHOUT ARRAY INDEXING 
Author Message
 Multiply and Add matrices with 2d array WITHOUT ARRAY INDEXING

I have these functions that I am trying to write.
void fill_zero(int *mat);
void read_matrix(int *mat);
void add(int *mat1, int *mat2, int *mat3);
void multiply(int *mat1, int *mat2, int *mat3);
void print(int *mat1, int *mat2, int *mat3);

1.The problem is how do multiply  the matrices without using array indexing.
How do a read and store the data for two matrices without using array
indexing.
The matrices to  be read are 3x3.
My main problem is the array indexing.

Any help will be much appreciated.
Thank you



Sat, 03 Sep 2005 14:05:21 GMT  
 Multiply and Add matrices with 2d array WITHOUT ARRAY INDEXING

Quote:

> I have these functions that I am trying to write.
> void fill_zero(int *mat);
> void read_matrix(int *mat);
> void add(int *mat1, int *mat2, int *mat3);
> void multiply(int *mat1, int *mat2, int *mat3);
> void print(int *mat1, int *mat2, int *mat3);

> 1.The problem is how do multiply  the matrices without using array indexing.
> How do a read and store the data for two matrices without using array
> indexing.
> The matrices to  be read are 3x3.
> My main problem is the array indexing.

Depends what you mean with array indexing. Theoretically speaking,
whenever you look something up in a table using an index you are
indexing. If you mean without using the index operator [] then you
have to use pointer arithmetic. Something like

*(mat1 + i + 3 * j)

might do the trick. But it is ugly ugly ugly.

--
Thomas.



Sat, 03 Sep 2005 15:55:19 GMT  
 Multiply and Add matrices with 2d array WITHOUT ARRAY INDEXING

Quote:

> I have these functions that I am trying to write.
> void fill_zero(int *mat);
> void read_matrix(int *mat);
> void add(int *mat1, int *mat2, int *mat3);
> void multiply(int *mat1, int *mat2, int *mat3);
> void print(int *mat1, int *mat2, int *mat3);

> 1.The problem is how do multiply  the matrices without using array indexing.
> How do a read and store the data for two matrices without using array
> indexing.
> The matrices to  be read are 3x3.
> My main problem is the array indexing.

Start with a better interface.  Somewhere you have defined the
storage those matN pointers point to, with say an xdim and a
ydim.  Pass those values in your function calls.  Then the
function has the information needed to process the values.

ex:  void fill_zero(int *mat, size_t xdim, size_t ydim);

I wouldn't worry about whether or not you use array indexing.  The
compiler can probably optimize the code quite nicely by itself,
and if it can't you can then worry about it without affecting any
other code.

--

   Available for consulting/temporary embedded and systems.
   <http://cbfalconer.home.att.net>  USE worldnet address!



Sun, 04 Sep 2005 00:44:20 GMT  
 Multiply and Add matrices with 2d array WITHOUT ARRAY INDEXING

Quote:

> I have these functions that I am trying to write.
> void fill_zero(int *mat);
> void read_matrix(int *mat);
> void add(int *mat1, int *mat2, int *mat3);
> void multiply(int *mat1, int *mat2, int *mat3);
> void print(int *mat1, int *mat2, int *mat3);

> 1.The problem is how do multiply  the matrices without using array indexing.
> How do a read and store the data for two matrices without using array
> indexing.

What is wrong with using "array indexing"?
Is this just an artificial limitation you made for yourself
to make the task harder, or is this some kind a homework
assignment? If it is homework, ask the teacher questions.
If it is an artificial limitation, then why?

The answers to these questions will help us understand more
of what/why you are doing this, and will probably lead to a
more useful answer.

Quote:
> The matrices to  be read are 3x3.
> My main problem is the array indexing.

> Any help will be much appreciated.
> Thank you



Sun, 04 Sep 2005 04:15:34 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Which 2D array of 2D array addressing method?

2. 2D array of pointers to 2D arrays

3. use 1d array + macro or 2d array?

4. How To pass 2D String array to VB from VC++ Using Safe array

5. Fast array transfer with 2D arrays...?

6. add and multiply matrices with pointer Arithmetic help.

7. array index of smallest number in array?

8. Using array index in array initialization list's

9. array indexing by pointer and long index

10. Question about adding an array to existing array.

11. gcc: bug with const and multiply-dimensioned arrays?

12. Multiply 2 large numbers in arrays

 

 
Powered by phpBB® Forum Software