ncnt = 0 !计数器,非零元素的个数
do i = 1,n
do j = 1,n
if (A(i,j) /=0) then
ncnt =ncnt +1
endif
enddo
enddo
allocate(vec(ncnt))
ncnt = 0
do i = 1,n
do j = 1,n
if (A(i,j) /=0) then
ncnt =ncnt +1
vec(ncnt) = A(i,j)
endif
enddo
enddo
http://people.sc.fsu.edu/~jburkardt/c_src/csparse/csparse.html
Tim Davis写的基于C的稀疏矩阵计算库,也是MATLAB的稀疏矩阵库的早期版本
配合Direct Methods for Sparse Linear Systems, Timothy A. Davis, SIAM, Philadelphia, Sept. 2006.
愿意花半年把这本书啃掉,并拿下C与F混合编程,lz在中国大陆地区的稀疏矩阵编程与计算个人能力排名挤进前25%毫无压力