# Matrix data type+

• 03-25-2001, 12:03 PM
Mike
Matrix data type+

Hi,

I'm creating a matrix data type. A matrix is a structure that stores elements
in rows and columns.

For Example: | 1 2 3 |
| 5 4 3 |
| 3 0 8 |

I'm wondering how I should store the data internally. Should I use a single
dimentional or 2-dimensional array.
Which one do you think is faster or better?

Thanks

Mike
• 03-26-2001, 01:25 AM
Scott
Re: Matrix data type+

I am doing the same thing!!! I am debating whether to use arrays like you
say, but I am also thinking about a vector of vectors... just because I think
memory issues will be easier to handle. I have built two Vector classes,
1 using arrays and the other with vectors... They both work perfectly, but
I found the one implemented with vectors easier to program (although I did
it after I finished one using arrays).

Sorry that doesn't answer your question... it's just neat to see people with
similar projects :)

Scott

"Mike" <Mjg_01@yahoo.com> wrote:
>
>Hi,
>
>I'm creating a matrix data type. A matrix is a structure that stores elements
>in rows and columns.
>
>For Example: | 1 2 3 |
> | 5 4 3 |
> | 3 0 8 |
>
>I'm wondering how I should store the data internally. Should I use a single
>dimentional or 2-dimensional array.
>Which one do you think is faster or better?
>
>Thanks
>
>Mike

• 03-26-2001, 01:44 AM
Re: Matrix data type+

I feel usage of two-dimensional array is better.

>> I'm wondering how I should store the data internally.

For ex: int mat[2][3];

where number 2 refers to number of rows count and 3 refers to the number of
columns and
you can access the first matrix element by mat[1][1] and the rest like that.

with regards
shesh

Mike wrote:

> Hi,
>
> I'm creating a matrix data type. A matrix is a structure that stores elements
> in rows and columns.
>
> For Example: | 1 2 3 |
> | 5 4 3 |
> | 3 0 8 |
>
> I'm wondering how I should store the data internally. Should I use a single
> dimentional or 2-dimensional array.
> Which one do you think is faster or better?
>
> Thanks
>
> Mike

• 03-26-2001, 08:25 AM
jonnin
Re: Matrix data type+

Single is easier for some operations, 2d is easier for access /human thought.
I posted a full set with single a couple of days back, for something to
compare it to. The internal speed is not different either way. At the time,
single seemed easier for dynamic allocation, and for the operations I was
doing.

"Mike" <Mjg_01@yahoo.com> wrote:
>
>Hi,
>
>I'm creating a matrix data type. A matrix is a structure that stores elements
>in rows and columns.
>
>For Example: | 1 2 3 |
> | 5 4 3 |
> | 3 0 8 |
>
>I'm wondering how I should store the data internally. Should I use a single
>dimentional or 2-dimensional array.
>Which one do you think is faster or better?
>
>Thanks
>
>Mike

• 03-26-2001, 08:30 AM
jonnin
Re: Matrix data type+

This is true, but 2*number of cols + 3 is the same thing, and the math is
the same internally. And use [0][0] for first one? (changes the indices
above, but same again), again, see the code I sent last week.

>
>I feel usage of two-dimensional array is better.
>
>>> I'm wondering how I should store the data internally.

>For ex: int mat[2][3];
>
>where number 2 refers to number of rows count and 3 refers to the number

of
>columns and
>you can access the first matrix element by mat[1][1] and the rest like that.
>
>with regards
> shesh
>
>
>Mike wrote:
>
>> Hi,
>>
>> I'm creating a matrix data type. A matrix is a structure that stores

elements
>> in rows and columns.
>>
>> For Example: | 1 2 3 |
>> | 5 4 3 |
>> | 3 0 8 |
>>
>> I'm wondering how I should store the data internally. Should I use a

single
>> dimentional or 2-dimensional array.
>> Which one do you think is faster or better?
>>
>> Thanks
>>
>> Mike

>

• 03-26-2001, 12:19 PM
nick
Re: Matrix data type+

I would make a 2-d array, if you use a 2-d vector it would be the same as
an 2-d array...vectors are just implemented in the STL. If you're looking
for ease of use, use the vector

"Mike" <Mjg_01@yahoo.com> wrote:
>
>Hi,
>
>I'm creating a matrix data type. A matrix is a structure that stores elements
>in rows and columns.
>
>For Example: | 1 2 3 |
> | 5 4 3 |
> | 3 0 8 |
>
>I'm wondering how I should store the data internally. Should I use a single
>dimentional or 2-dimensional array.
>Which one do you think is faster or better?
>
>Thanks
>
>Mike

• 03-27-2001, 05:20 AM
Andrea Gagliardi La Gala
Re: Matrix data type+

I think it's worthwile remembering you all that you're programmin in C++,
that is not C!
The most efficient and elegant way to do tour task is using STL valarray
(an improved vector to perform efficient mathematical computations) and STL
slices (that is, setting dimensions in your array to have matrices).
Bye,
-Andrea

"Scott" <particleman@chalktv.com> wrote:
>
>I am doing the same thing!!! I am debating whether to use arrays like you
>say, but I am also thinking about a vector of vectors... just because I

think
>memory issues will be easier to handle. I have built two Vector classes,
>1 using arrays and the other with vectors... They both work perfectly, but
>I found the one implemented with vectors easier to program (although I did
>it after I finished one using arrays).
>
>Sorry that doesn't answer your question... it's just neat to see people

with
>similar projects :)
>
>Scott
>
>
>"Mike" <Mjg_01@yahoo.com> wrote:
>>
>>Hi,
>>
>>I'm creating a matrix data type. A matrix is a structure that stores elements
>>in rows and columns.
>>
>>For Example: | 1 2 3 |
>> | 5 4 3 |
>> | 3 0 8 |
>>
>>I'm wondering how I should store the data internally. Should I use a single
>>dimentional or 2-dimensional array.
>>Which one do you think is faster or better?
>>
>>Thanks
>>
>>Mike

>