CrazyEngineers
  • rama_krish627
    rama_krish627

    MemberNov 17, 2008

    Sparse Matrix

    Hi
    Can any one tell me how to represent a Sparse Matrix using arrays.
    and also how to add two sparse matrices.😲
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • manupep

    MemberNov 18, 2008

    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.
    Are you sure? This action cannot be undone.
    Cancel
  • komputergeek

    MemberNov 19, 2008

    //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.
    Are you sure? This action cannot be undone.
    Cancel
  • niraj.kumar

    MemberNov 20, 2008

    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
    Are you sure? This action cannot be undone.
    Cancel
  • rama_krish627

    MemberNov 21, 2008

    ok fine I understood what it is.
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register