云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 稀疏矩阵乘法的运算

稀疏矩阵乘法的运算

  • 62 次阅读
  • 3 次下载
  • 2025/5/3 3:07:32

武汉理工大学《数据结构》课程设计说明书

ElemType data;//存储row行col列的元素的值 }DataNode;

采用结构体存储稀疏二维数组: typedef struct SparseMatrix {

DataType *matrix;//用数组存储非零元 int row;//二维数组的行数 int col;//二维数组的列数

int *rpos;//每行第一个非零元在matrix中的位置 int num;//非零元的个数 int con;//指定常数

};

注:在第二个结构体中num和con这两个变量,在本此系统中con默认为0,num的功能是检验数据是否完整。当二维数组中出现很多非零元素值一样的时候,也可以采用三元组的方法存储,只要让con等于那个非零元素值即可。

7.算法描述:

本系统的主要算法为稀疏矩阵的乘法运算。 算法如下: Q初始化;

if (Q是非零矩阵) {//逐行求积

for(arow=1;arow<=M.row;++arow) {//处理M的每一行

ctemp[]=0;//累加器清零

计算Q中第arow行的积并存入ctemp[]中; 将ctemp[]中的非零元压缩存储到Q.matrix中; } }

3

武汉理工大学《数据结构》课程设计说明书

8.测试结果与分析:

测试1:两个文件数据完全正确

Input the method of getting data(1 is from file,2 is from inputting):1 Input two names of the data file:data1.txt data2.txt Read the first file successfully! Read the second file successfully! The first matrix is: 1 1 3 1 4 5 2 2 -1 3 1 2

The second matrix is: 1 2 2 2 1 1 3 1 -2 3 2 4 The result is: 3 0 3 2 1 2 6 2 1 -1 3 2 4

Input one name of the data file:data5.txt

测试2:一个文件数据完全正确,另一个文件数据不正确 Input the method of getting data(1 is from file,2 is from inputting):1 Input two names of the data file:data1.txt data4.txt Read the first file successfully! The data is wrong! The first data is wrong!

4

武汉理工大学《数据结构》课程设计说明书

Please check it carefully,then input it again: 1 2 2

The data is wrong! The 4th data is wrong!

Please check it carefully,then input it again: 3 2 4

Read the second file successfully! The first matrix is: 1 1 3 1 4 5 2 2 -1 3 1 2

The second matrix is: 1 2 2 2 1 1 3 1 -2 3 2 4 The result is: 3 0 3 2 1 2 6 2 1 -1 3 2 4

Input one name of the data file:data6.txt 测试3:两个数据文件都错误

Input the method of getting data(1 is from file,2 is from inputting):1 Input two names of the data file:data3.txt data4.txt The data is wrong! The second data is wrong!

Please check it carefully,then input it again:

5

武汉理工大学《数据结构》课程设计说明书

1 4 5

The data is wrong! The 4th data is wrong!

Please check it carefully,then input it again: 3 1 2

Read the first file successfully! The data is wrong! The first data is wrong!

Please check it carefully,then input it again: 1 2 2

The data is wrong! The 4th data is wrong!

Please check it carefully,then input it again: 3 2 4

Read the second file successfully! The first matrix is: 1 1 3 1 4 5 2 2 -1 3 1 2

The second matrix is: 1 2 2 2 1 1 3 1 -2 3 2 4 The result is: 3 0 3 2 1 2 6 2 1 -1

6

搜索更多关于: 稀疏矩阵乘法的运算 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

武汉理工大学《数据结构》课程设计说明书 ElemType data;//存储row行col列的元素的值 }DataNode; 采用结构体存储稀疏二维数组: typedef struct SparseMatrix { DataType *matrix;//用数组存储非零元 int row;//二维数组的行数 int col;//二维数组的列数 int *rpos;//每行第一个非零元在matrix中的位置 int num;//非零元的个数 int con;//指定常数 }; 注:在第二个结构体中num和con这两个变量,在本此系统中con默认为0,num的功能是检验数

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com