suffer 发表于 2015-11-3 09:12

用两种不同方式创建三对角稀疏矩阵

n=5;SM1=sparse(1:n,1:n,-2*ones(1,n),n,n,n);
SM2=sparse(2:n,1:n-1,ones(1,n-1),n,n,n-1);S1=SM1+SM2+SM2'
e=ones(n,1);S2=spdiags(,[-1,0,1],n,n),SF=full(S1)
S1 =
(1,1) -2
(2,1) 1
(1,2) 1
(2,2) -2
(3,2) 1
(2,3) 1
(3,3) -2
(4,3) 1
(3,4) 1
(4,4) -2
(5,4) 1
(4,5) 1
(5,5) -2

S2 =
(1,1) -2
(2,1) 1
(1,2) 1
(2,2) -2
(3,2) 1
(2,3) 1
(3,3) -2
(4,3) 1
(3,4) 1
(4,4) -2
(5,4) 1
(4,5) 1
(5,5) -2

SF =
-2 1 0 0 0
1 -2 1 0 0
0 1 -2 1 0
0 0 1 -2 1
0 0 0 1 -2
页: [1]
查看完整版本: 用两种不同方式创建三对角稀疏矩阵