| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 993 人关注过本帖
标题:关于稀疏矩阵加减乘
只看楼主 加入收藏
营养书
Rank: 2
等 级:论坛游民
帖 子:25
专家分:29
注 册:2011-4-17
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:10 
关于稀疏矩阵加减乘
我这个代码加减都可以了,就是乘法出不来,看了好久,实在不会,求高手指教。


#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 50
//三元组结构
typedef struct
{
  int r,c;  //矩阵行下标和列下标
  int v;   //值
}Triple;
//矩阵结构
typedef struct
{
    Triple data[MAXSIZE];
    int num[MAXSIZE];//存放各行非零元个数
    int rops[MAXSIZE+1];    //存放各行第一个非零元在矩阵中的位置
    int mu,nu,tu;    //矩阵的行数、列数、非零元个数
}matrix;

//输入矩阵
void Init(matrix *M)
{
   int i;
   int u,v;
   int p[8][8];
   if(M->mu<1||M->nu<1||M->tu>M->mu*M->nu)
   {
       printf("出错\n");
   }
   for(u=1;u<=M->mu;u++)
    for(v=1;v<=M->nu;v++)
       p[u][v]=0;
  for(i=1;i<=M->tu;i++)
  {
      printf("第%d个非零元的行号:",i);
      scanf("%d",&M->data[i].r);
      printf("\n");
      printf("第%d个非零元得列号:",i);
      scanf("%d",&M->data[i].c);
      printf("\n");
      printf("第个非零元的值:",i);
      scanf("%d",&M->data[i].v);
      p[M->data[i].r][M->data[i].c]=M->data[i].v;
  }
  printf("\n");
  printf("您创建的矩阵如下:\n");
  for(u=1;u<=M->mu;u++)
  {for(v=1;v<=M->nu;v++)
    { printf("%d ",p[u][v]);}
    printf("\n");
   
  }   
}

int Add(matrix *M,matrix *T,matrix *G)
{  int sum;
   int i = 1, j = 1, k = 1;    //i, j, k分别用以保存A、B、C非零元素个数
   int u,v;
   int p[8][8];
   for(u=1;u<=M->mu;u++)
    for(v=1;v<=M->nu;v++)
       p[u][v]=0;
  if (M->mu !=T->mu || M->mu != T->nu)
    {
        printf( "两个稀疏矩阵的大小不等,不能相加!\n");
        return 0;
    }
  
    if (M->mu ==T->mu && M->nu ==T->nu)
    {
        while (i<=M->tu && j<=T->tu)
        {
            if (M->data[i].r==T->data[j].r)
            {
                if (M->data[i].c <T->data[j].c)
                {
                    G->data[k].r=M->data[i].r;
                    G->data[k].c=M->data[i].c;
                    p[G->data[k].r][G->data[k].c]=M->data[i].v;
                    k++;
                    i++;
                }
                else if (M->data[i].c > T->data[j].c)
                {
                    G->data[k].r=T->data[j].r;
                    G->data[k].c=T->data[j].c;
                    p[G->data[k].r][G->data[k].c]=T->data[j].v;
                    k++;
                    j++;
                }
                else
                {
                    sum=M->data[i].v+T->data[j].v;
                    if (sum!= 0)
                    {
                        G->data[k].r=M->data[i].r;
                        G->data[k].c=M->data[i].c;
                        p[G->data[k].r][G->data[k].c]=sum;
                        k++;
                    }
                    i++;
                    j++;
                }
            }//end_if
            else if (M->data[i].r < T->data[j].r)
            {
                G->data[k].r=M->data[i].r;
                G->data[k].c=M->data[i].c;
                p[G->data[k].r][G->data[k].c]=M->data[i].v;
                k++;
                i++;
            }
            else
            {
                G->data[k].r=T->data[j].r;
                G->data[k].c=T->data[j].c;
                p[G->data[k].r][G->data[k].c]=T->data[j].v;
                k++;
                j++;
            }
            //把剩余部分元素存入C中
            if (i>M->tu&&j<=T->tu)
            {
                for (; j <= T->tu; j++)
                {
                    G->data[k].r = T->data[j].r;
                    G->data[k].c = T->data[j].c;
                    p[G->data[k].r][G->data[k].c] = T->data[j].v;
                    k++;
                }
            }
            if (i <= M->tu && j > T->tu)
            {
                for (; i <= M->tu; i++)
                {
                    G->data[k].r = M->data[i].r;
                    G->data[k].c = M->data[i].c;
                    p[G->data[k].r][G->data[k].c] = M->data[i].v;
                    k++;
                }
            }
        }//end_while
        G->mu = M->mu;
        G->nu = M->nu;
        G->tu = k-1;
       printf("输出两个稀疏矩阵的和: \n");
       for(u=1;u<=M->mu;u++)
        { for(v=1;v<=M->nu;v++)
      { printf("%d ",p[u][v]);}
      printf("\n");
   
        }   
        return 1;
    }//end_if
    else
        return 0;
}

int Jian(matrix *M,matrix *T,matrix *G)

{  int sum;
   int i = 1, j = 1, k = 1;    //i, j, k分别用以保存A、B、C非零元素个数
 int u,v;
   int p[8][8];
   for(u=1;u<=M->mu;u++)
    for(v=1;v<=M->nu;v++)
       p[u][v]=0;
  if (M->mu !=T->mu || M->mu != T->nu)
    {
        printf( "两个稀疏矩阵的大小不等,不能相减!\n");
        return 0;
    }
  
    if (M->mu ==T->mu && M->nu ==T->nu)
    {
        while (i<=M->tu && j<=T->tu)
        {
            if (M->data[i].r==T->data[j].r)
            {
                if (M->data[i].c <T->data[j].c)
                {
                    G->data[k].r=M->data[i].r;
                    G->data[k].c=M->data[i].c;
                    p[G->data[k].r][G->data[k].c]=M->data[i].v;
                    k++;
                    i++;
                }
                else if (M->data[i].c > T->data[j].c)
                {
                    G->data[k].r=T->data[j].r;
                    G->data[k].c=T->data[j].c;
                    p[G->data[k].r][G->data[k].c]=T->data[j].v;
                    k++;
                    j++;
                }
                else
                {
                    sum=M->data[i].v-T->data[j].v;
                    if (sum!= 0)
                    {
                        G->data[k].r=M->data[i].r;
                        G->data[k].c=M->data[i].c;
                        p[G->data[k].r][G->data[k].c]=sum;
                        k++;
                    }
                    i++;
                    j++;
                }
            }//end_if
            else if (M->data[i].r < T->data[j].r)
            {
                G->data[k].r=M->data[i].r;
                G->data[k].c=M->data[i].c;
                p[G->data[k].r][G->data[k].c]=M->data[i].v;
                k++;
                i++;
            }
            else
            {
                G->data[k].r=T->data[j].r;
                G->data[k].c=T->data[j].c;
                p[G->data[k].r][G->data[k].c]=T->data[j].v;
                k++;
                j++;
            }
            //把剩余部分元素存入C中
            if (i>M->tu&&j<=T->tu)
            {
                for (; j <= T->tu; j++)
                {
                    G->data[k].r = T->data[j].r;
                    G->data[k].c = T->data[j].c;
                    p[G->data[k].r][G->data[k].c] = -T->data[j].v;
                    k++;
                }
            }
            if (i <= M->tu && j > T->tu)
            {
                for (; i <= M->tu; i++)
                {
                    G->data[k].r = M->data[i].r;
                    G->data[k].c = M->data[i].c;
                    p[G->data[k].r][G->data[k].c] = M->data[i].v;
                    k++;
                }
            }
        }//end_while
        G->mu = M->mu;
        G->nu = M->nu;
        G->tu = k-1;
        printf("输出两个稀疏矩阵的差: \n");
       for(u=1;u<=M->mu;u++)
       {  for(v=1;v<=M->nu;v++)
       { printf("%d ",p[u][v]);}
        printf("\n");
       }   
        return 1;
    }//end_if
    else
        return 0;
}
//输出矩阵,按标准格式输出





int Cheng(matrix *M,matrix *T,matrix *G)
{ int u,v,w,k;
  int p1[MAXSIZE+1][MAXSIZE+1];
  for(u=1;u<=M->mu;u++)
  {for(v=1;v<=M->nu;v++)
       p1[u][v]=0;
  }
  if (M->nu!= T->mu)
    {
       printf("不能相乘\n");
        return 1;
    }
    //Q的初始化
    G->mu=M->mu;
    G->nu=T->nu;
    G->tu=0;
    int mrow, nrow, p, q, t, tp, qcol;
    int ctemp[MAXSIZE+1];
    for(mrow=1;mrow<M->mu;mrow++)  //清零
  {
      M->num[mrow]=0;
  }
  for(w=1;w<=M->tu;w++)   //M中的非零个数
  {
      k=M->data[w].r;
      M->num[k]++;
  }
  M->rops[1]=1;  //第一行第一个非零元的位置在data[]的第一位
 for(mrow=2;mrow<=M->mu;mrow)
 {
     M->rops[mrow]=M->rops[mrow-1]+M->num[mrow-1];
 }
 
//记录矩阵T中各行非零元的个数
 for(nrow=1;nrow<T->mu;nrow++)  //清零
 {
     T->num[nrow]=0;
 }
 for(w=1;w<=T->tu;w++)     //T中的非零个数
 {
     k=T->data[w].r;
     T->num[k]++;
 }
T->rops[1]=1;    //第一行第一个非零元的位置在data的第一位
 for(nrow=2;nrow<=T->mu;nrow++)
 {
   T->rops[nrow]=T->rops[nrow-1]+T->num[nrow-1];
 }
 
    //辅助数组
    //如果Q是非零矩阵
    if (M->tu*T->tu!=0)
    {
        for (mrow=1; mrow<= M->mu;++mrow)
        {
            //当前行各元素累加器清零
            for(int x=1;x<=T->nu;x++)
            {ctemp[x];}
            //end_x
            //当前行的首个非零元素在三元组中的位置为此行前所有非0元素加1
            G->rops[mrow]=G->tu+1;
            if (mrow<M->mu)
            {
                tp=M->rops[mrow+1];
            }
            else
                tp=M->tu+1;
            for (p=M->rops[mrow]; p<tp;++p)        //对当前行的每个非零元素操作
            {
                nrow=M->data[p].c;        //在N中找到与M操作元素的c值相等的行值r
                if (nrow<T->mu)
                {
                    t = T->rops[nrow+1];
                }
                else
                    t = T->tu+1;
                //对找出的行的每个非零元素进行操作
                for (q = T->rops[nrow];q<t;++q)
                {
                    qcol = T->data[q].c;
                    //将乘得到的对应值放在相应元素的累加器里面
                    ctemp[qcol] += M->data[p].v*T->data[q].v;
                }
            }//p_end_for
            
            //对已经求出的累加器中的值压缩到Q中
            for (qcol=1;qcol<=T->nu;qcol++)
            {
                    if (++T->tu>MAXSIZE)
                    {
                        printf("错误\n");
                          return 1;
                    }
                if (ctemp[qcol])
                {
                     
                    G->data[G->tu].r = mrow;
                    G->data[G->tu].c = qcol;
                    p1[G->data[G->tu].r][G->data[G->tu].c] = ctemp[qcol];
                    
                  
                }
            }//qcol_end_for
        }//arow_end_for
    }//end_if
    printf("两矩阵相乘的结果为:\n");

   for(u=1;u<=M->mu;u++)
    {  for(v=1;v<=M->nu;v++)
    {printf("%d ",p1[u][v]);}
    printf("\n");
    }

  return 0;  
}



int main()
{
  matrix *M=(matrix*)malloc(sizeof(matrix));
  matrix *T=(matrix*)malloc(sizeof(matrix));
  matrix *G=(matrix*)malloc(sizeof(matrix));
  int tag=1;
  int n;
   printf("请输入第一个矩阵的行数和列数及非零元的个数:");
   scanf("%d%d%d",&(M->mu),(&M->nu),(&M->tu));
   
   Init(M);
   printf("\n");

   printf("请输入第一个矩阵的行数和列数及非零元的个数:");
   scanf("%d%d%d",&(T->mu),(&T->nu),(&T->tu));
   Init(T);
   printf("\n");

  while(tag)
  {
      printf("请输入相加(1)、相减(2)、相乘(3)、退出(4)");
      printf("\n");
      scanf("%d",&n);
      switch(n)
      {
        case 1:Add(M,T,G);break;
        case 2:Jian(M,T,G);break;
        case 3:Cheng(M,T,G);break;
        case 4:tag=0;
      }
  }
  return 0;
}
搜索更多相关主题的帖子: 三元 
2011-04-17 19:32
诸葛修勤
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:11
帖 子:549
专家分:1955
注 册:2010-10-28
收藏
得分:0 
表示有压力啊
2011-04-17 19:46
寒风中的细雨
Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17
等 级:贵宾
威 望:66
帖 子:1710
专家分:8645
注 册:2009-9-15
收藏
得分:0 
顶上去
2011-04-18 09:28
寒风中的细雨
Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17
等 级:贵宾
威 望:66
帖 子:1710
专家分:8645
注 册:2009-9-15
收藏
得分:20 
程序代码:
#include <stdio.h>
#include <stdlib.h>

#define MAX_SIZE 50
#define DIM_ROW    8
#define DIM_COL 8

typedef struct
{
    int row;
    int col;
    int value;
}Triple;

typedef struct
{
    Triple m_data[MAX_SIZE];
    int m_num[DIM_ROW];//存放各行非零元个数
    int m_rops[DIM_ROW];//存放各行第一个非零元在矩阵中的位置
    int m_row;
    int m_col;
    int m_nonzero;
}Matrix;

//创建一个稀疏矩阵
Matrix * create_matrix()
{
    int index;
    Matrix *temp = NULL;

    temp = (Matrix*) malloc (sizeof(Matrix));
   
    if (NULL == temp)
    {//判断分配是否成功  堆栈溢出结束
        exit(0);
    }

    printf("\t请输入矩阵的行数和列数及非零元的个数: ");
    scanf("%d%d%d", &(temp->m_row), &(temp->m_col), &(temp->m_nonzero));
   
    if(temp->m_col<1 || temp->m_row<1 ||
       temp->m_nonzero > temp->m_col*temp->m_row)
    {
        printf("出错\n");
        exit(0);
    }

    for (index=1; index<=temp->m_row; ++index)
    {
        temp->m_num[index] = 0;//表示非零元数的个数在index行上为0
        temp->m_rops[index] = DIM_COL;//表示第一个非零元数的位置为DIM_COL
    }

    for (index=1; index<=temp->m_nonzero; ++index)
    {
        printf("第%d个非零元的行号:", index);
        scanf("%d", &(temp->m_data[index].row));
        temp->m_num[temp->m_data[index].row]++;//表示在此行上的非零元数个数加1
        printf("第%d个非零元得列号:", index);
        scanf("%d", &(temp->m_data[index].col));

        if (temp->m_rops[temp->m_data[index].row] == DIM_COL)
        {
            temp->m_rops[temp->m_data[index].row] = temp->m_data[index].col;//标记第一个非零元数列好
        }
        else
        {
            if (temp->m_rops[temp->m_data[index].row] > temp->m_data[index].col)
            {
                temp->m_rops[temp->m_data[index].row] = temp->m_data[index].col;//更新第一非零元数的位置
            }
        }

        printf("第%d个非零元的值:", index);
        scanf("%d", &(temp->m_data[index].value));

    }
    

    return temp;
}
//在控制台输出稀疏矩阵
void show_matrix(Matrix *temp)
{
    int index;
    int row, col;
    int p[DIM_ROW][DIM_COL] = {0};

    for (index=1; index<=temp->m_nonzero; ++index)
    {
        p[temp->m_data[index].row][temp->m_data[index].col] = temp->m_data[index].value;
    }

    printf("\t您创建的矩阵如下\n");
    for (row=1; row<=temp->m_row; ++row)
    {
        for (col=1; col<=temp->m_col; ++col)
        {
            printf("%d ", p[row][col]);
        }
        printf("\n");
    }
}

Matrix * process(int p[DIM_ROW][DIM_COL], Matrix *add_var, Matrix *pm_var_1, Matrix *pm_var_2)
{
    int counter;//计数器
    int index = 1;
    int row, col;

    for (row=1; row<=add_var->m_row; ++row)
    {
        add_var->m_num[row] = 0;
        add_var->m_rops[row] = DIM_COL;
        counter = 0;
        col = pm_var_1->m_rops[row] > pm_var_2->m_rops[row] ?
            pm_var_2->m_rops[row] : pm_var_1->m_rops[row];
        for (; col<=add_var->m_col; ++col)
        {
            if (0 != p[row][col])
            {
                add_var->m_nonzero++;
                add_var->m_data[index].col = col;
                add_var->m_data[index].row = row;
                add_var->m_data[index].value = p[row][col];
                add_var->m_num[row]++;
                if (add_var->m_rops[index] == DIM_COL)
                {
                    add_var->m_rops[index] = add_var->m_data[index].col;//标记第一个非零元数列好
                }
                else
                {
                    if (add_var->m_rops[index] > add_var->m_data[index].col)
                    {
                        add_var->m_rops[index] = add_var->m_data[index].col;//更新第一非零元数的位置
                    }
                }
                counter++;
                index++;
            }
            if (counter >= (pm_var_1->m_num[row]+pm_var_2->m_num[row]))
            {
                break;
            }
        }
    }

    return add_var;
}
//两个稀疏矩阵相加  返回相加后的结果
Matrix * add_matrix(Matrix *pm_var_1, Matrix *pm_var_2)
{
    int index;
    int p[DIM_ROW][DIM_COL] = {0};
    Matrix *add_var = NULL;

    //判断两个矩阵是否满足相加的条件
    if ((pm_var_1->m_col != pm_var_2->m_col) ||
        (pm_var_1->m_row != pm_var_2->m_row))
    {
        printf("\t两个稀疏矩阵的大小不等,不能相加!\n");
        exit(0);
    }

    add_var = (Matrix*) malloc (sizeof(Matrix));
    add_var->m_col = pm_var_1->m_col;
    add_var->m_row = pm_var_1->m_row;
    add_var->m_nonzero = 0;

    for (index=1; index<=pm_var_1->m_nonzero; ++index)
    {
        p[pm_var_1->m_data[index].row][pm_var_1->m_data[index].col] = pm_var_1->m_data[index].value;
    }

    for (index=1; index<=pm_var_2->m_nonzero; ++index)
    {
        if (0 == p[pm_var_2->m_data[index].row][pm_var_2->m_data[index].col])
        {
            p[pm_var_2->m_data[index].row][pm_var_2->m_data[index].col] = pm_var_2->m_data[index].value;
        }
        else
        {
            p[pm_var_2->m_data[index].row][pm_var_2->m_data[index].col] += pm_var_2->m_data[index].value;
        }
    }
    

    return process(p, add_var, pm_var_1, pm_var_2);
}
//相减
Matrix * sub_matrix(Matrix *pm_var_1, Matrix *pm_var_2)
{
    int index;
    int p[DIM_ROW][DIM_COL] = {0};
    Matrix *add_var = NULL;

    //判断两个矩阵是否满足相减的条件
    if ((pm_var_1->m_col != pm_var_2->m_col) ||
        (pm_var_1->m_row != pm_var_2->m_row))
    {
        printf("\t两个稀疏矩阵的大小不等,不能相减!\n");
        exit(0);
    }

    add_var = (Matrix*) malloc (sizeof(Matrix));
    add_var->m_col = pm_var_1->m_col;
    add_var->m_row = pm_var_1->m_row;
    add_var->m_nonzero = 0;

    for (index=1; index<=pm_var_1->m_nonzero; ++index)
    {
        p[pm_var_1->m_data[index].row][pm_var_1->m_data[index].col] = pm_var_1->m_data[index].value;
    }

    for (index=1; index<=pm_var_2->m_nonzero; ++index)
    {
        if (0 == p[pm_var_2->m_data[index].row][pm_var_2->m_data[index].col])
        {
            p[pm_var_2->m_data[index].row][pm_var_2->m_data[index].col] = -pm_var_2->m_data[index].value;
        }
        else
        {
            p[pm_var_2->m_data[index].row][pm_var_2->m_data[index].col] -= pm_var_2->m_data[index].value;
        }
    }

    return process(p, add_var, pm_var_1, pm_var_2);
}
//相乘
Matrix * mul_matrix(Matrix *pm_var_1, Matrix *pm_var_2)
{
    int sum;
    int counter;//计数器
    int index = 1;
    int row, col;
    int p1[DIM_ROW][DIM_COL] = {0};
    int p2[DIM_ROW][DIM_COL] = {0};
    Matrix *add_var = NULL;

    //判断两个矩阵是否满足相乘的条件
    if (pm_var_1->m_col != pm_var_2->m_row)
    {
        printf("\t两个稀疏矩阵的大小不等,不能相乘!\n");
        exit(0);
    }

    add_var = (Matrix*) malloc (sizeof(Matrix));
    add_var->m_col = pm_var_2->m_col;
    add_var->m_row = pm_var_1->m_row;
    add_var->m_nonzero = 0;

    for (index=1; index<=pm_var_1->m_nonzero; ++index)
    {
        p1[pm_var_1->m_data[index].row][pm_var_1->m_data[index].col] = pm_var_1->m_data[index].value;
    }

    for (index=1; index<=pm_var_2->m_nonzero; ++index)
    {
        p2[pm_var_2->m_data[index].row][pm_var_2->m_data[index].col] = pm_var_2->m_data[index].value;
    }

    counter = 1;
    for (row=1; row<=add_var->m_row; ++row)
    {
        add_var->m_num[row] = 0;
        add_var->m_rops[row] = DIM_COL;
        for (index=1; index<=pm_var_2->m_col; ++index)
        {   
            sum = 0;//求和
            col = pm_var_1->m_rops[row];//求出列数 第一个不为零的
            for (; col<=pm_var_2->m_row; ++col)
            {
                sum += p1[row][col]*p2[col][index];
            }

            if (0 != sum)
            {
                add_var->m_nonzero++;
                add_var->m_data[counter].col = index;
                add_var->m_data[counter].row = row;
                add_var->m_data[counter].value = sum;
                add_var->m_num[row]++;

                if (add_var->m_rops[index] == DIM_COL)
                {
                    add_var->m_rops[index] = add_var->m_data[index].col;//标记第一个非零元数列好
                }

                counter++;
            }
        }
    }
   
    return add_var;
}
//销毁矩阵
Matrix * destroy_matrix(Matrix *temp)
{
    free(temp);

    temp = NULL;

    return temp;
}

int main(void)
{
    Matrix *pm_var_1 = NULL;
    Matrix *pm_var_2 = NULL;
    Matrix *pm_var_3 = NULL;

    //创建第一个矩阵
    pm_var_1 = create_matrix();
    show_matrix(pm_var_1);
    //创建第二个矩阵
    pm_var_2 = create_matrix();
    show_matrix(pm_var_2);
/*    //加法
    pm_var_3 = add_matrix(pm_var_1, pm_var_2);
    show_matrix(pm_var_3);
    //释放掉内存
    pm_var_3 = destroy_matrix(pm_var_3);
    //减法
    pm_var_3 = sub_matrix(pm_var_1, pm_var_2);
    show_matrix(pm_var_3);
    //释放掉内存
    pm_var_3 = destroy_matrix(pm_var_3);*/
    //乘法
    pm_var_3 = mul_matrix(pm_var_1, pm_var_2);
    show_matrix(pm_var_3);
   
    pm_var_1 = destroy_matrix(pm_var_1);
    pm_var_2 = destroy_matrix(pm_var_2);
    pm_var_3 = destroy_matrix(pm_var_3);
    printf("\n");

    return 0;
}
2011-04-18 20:24
寒风中的细雨
Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17
等 级:贵宾
威 望:66
帖 子:1710
专家分:8645
注 册:2009-9-15
收藏
得分:0 
图片附件: 游客没有浏览图片的权限,请 登录注册

乘法截图
2011-04-18 20:25
寒风中的细雨
Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17
等 级:贵宾
威 望:66
帖 子:1710
专家分:8645
注 册:2009-9-15
收藏
得分:0 
加减法的实现算法应该非常简单
乘 的算法相对复杂一点 不过也有其简单的地方

测试数据
图片附件: 游客没有浏览图片的权限,请 登录注册

图片附件: 游客没有浏览图片的权限,请 登录注册
2011-04-18 20:31
寒风中的细雨
Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17
等 级:贵宾
威 望:66
帖 子:1710
专家分:8645
注 册:2009-9-15
收藏
得分:0 
加法:
图片附件: 游客没有浏览图片的权限,请 登录注册

减法:
图片附件: 游客没有浏览图片的权限,请 登录注册

乘法:
图片附件: 游客没有浏览图片的权限,请 登录注册

2011-04-18 20:36
营养书
Rank: 2
等 级:论坛游民
帖 子:25
专家分:29
注 册:2011-4-17
收藏
得分:0 
回复 4楼 寒风中的细雨



       非常感谢。。。。。。。。。。
2011-04-19 22:25
寒风中的细雨
Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17
等 级:贵宾
威 望:66
帖 子:1710
专家分:8645
注 册:2009-9-15
收藏
得分:0 
不错 没怎么加注释 能够理解
2011-04-20 06:47
营养书
Rank: 2
等 级:论坛游民
帖 子:25
专家分:29
注 册:2011-4-17
收藏
得分:0 
if (M->m_rops[index] == DIM_COL)
                {
                    M->m_rops[index] = M->m_data[index].col;//标记第一个非零元数列好
                }
                else
                {
                    if (M->m_rops[index] > M->m_data[index].col)
                    {
                        M->m_rops[index] = M->m_data[index].col;//更新第一非零元数的位置
                    }
                }

问一下这个语句是什么意思?为什么要开始把M->m_rops[index]赋值为DIM_COL??
2011-04-21 22:43
快速回复:关于稀疏矩阵加减乘
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.047409 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved