+ Reply to Thread
Results 1 to 5 of 5

Sparse Matrix

This is a discussion on Sparse Matrix within the Computer Science & IT Engineering forums, part of the CE : Technical Discussions category; Hi Can any one tell me how to represent a Sparse Matrix using arrays. and also how to add two ...

  1. #1
    CE - Apprentice rama_krish627's Avatar
    Join Date
    20th August 2008
    I'm a crazy: computer science engineer

    Posts
    34

    Exclamation Sparse Matrix

    Hi
    Can any one tell me how to represent a Sparse Matrix using arrays.
    and also how to add two sparse matrices.

  2. #2
    CE - Apprentice
    Join Date
    8th August 2007
    I'm a crazy: Computer Science engineer

    Location
    Kerala
    Posts
    11

    Default Re: Sparse Matrix

    sparse matrix is a matrix contain large no of elements but most of them are zeros("0") . So inorder to save the memory utilization we are not storing the zeros, only othr elements. Any sparse matrix has only 3 colums . but the row number depends on the number of non-zero elements.

    format is

    <row-no> <column-no> <value>
    <row-no> <column-no> <value>
    -------------------------------
    eg:

    3 0
    0 8 reprents in sparse form as

    0 0 3
    1 1 8

    I cant explain the whole procedure of adding becz i'min office now

    first you make sure that order of 3 matx are same. then sameposition elements should be added and make the resultant. I think u can able to make the logic.

  3. #3
    CE - Addict komputergeek's Avatar
    Join Date
    21st October 2008
    I'm a crazy: IT engineer

    Location
    India
    Posts
    250

    Default Re: Sparse Matrix

    Code:
    //Addition
    
    k=n2;
    for(i=0;i<n1;i++)
    {
          flag=0;
          for(j=0;j<n2;j++)
          {
                if( a[i][0] == b[j][0] && a[i][1]==b[j][1] )
                {
                        flag=1;
                        break;
                 }
          }
          if( flag==1)
                 b[j][2]=b[j][2] + a[i][2];
          else
           {
                 b[k][0]=a[i][0];
                 b[k][1]=a[i][1];
                 b[k][2]=a[i][2];
                 b[k][0]=b[i][0];
                 b[k][1]=b[i][1];
                 b[k][2]=b[i][2];
                 k++;
            }
    }
    
    //result of addition is stored in b
    
    This is just a logic.I haven't compiled the code.So expect errors in it
    Let me know if it works.
    IF YOU CAN'T Convince THEM ...
    CONFUSE THEM ...
    mail me at : komputergeek[at]crazyengineers[dot]net
    visit my website : http://www.techbrisk.com

  4. #4
    CE - Regular Member
    Join Date
    24th July 2008
    I'm a crazy: Computer engineer

    Posts
    64

    Default Re: Sparse Matrix

    just want to add ... the purpose of sparse matrix is 2 save memory and it is used when you have few information is a big space. So to preserve the memory we use sparse matrix

  5. #5
    CE - Apprentice rama_krish627's Avatar
    Join Date
    20th August 2008
    I'm a crazy: computer science engineer

    Posts
    34

    Default Re: Sparse Matrix

    ok fine I understood what it is.

+ Reply to Thread

LinkBacks (?)

  1. 8th December 2008, 05:35 PM
  2. 18th November 2008, 06:21 PM

Similar Threads

  1. iPhone 3G has a hidden data matrix code
    By CE-InFocus in forum CE - InFocus
    Replies: 0
    Last Post: 19th September 2008, 02:26 PM
  2. problem in matrix multiplication
    By sahana in forum Computer Science & IT Engineering
    Replies: 4
    Last Post: 19th March 2008, 12:20 AM
  3. Hello from Matrix
    By matrix in forum CE - Introductions
    Replies: 4
    Last Post: 2nd July 2007, 01:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts