Matrix data type+


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: Matrix data type+

  1. #1
    Mike Guest

    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

  2. #2
    Scott Guest

    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



  3. #3
    Sheshadri Iyengar Guest

    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



  4. #4
    jonnin Guest

    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



  5. #5
    jonnin Guest

    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.


    Sheshadri Iyengar <sheshadri.i@kshema.com> wrote:
    >
    >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

    >



  6. #6
    nick Guest

    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



  7. #7
    Andrea Gagliardi La Gala Guest

    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

    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center