稀疏矩阵生成: function [a, b] = aparsesetup(n) e = ones(n, 1); n2 = n / 2; a = spdiags([-e 3*e -e], -1:1, n, n); a(n2+1, n2) = -1; a(n2, n2+1) = -1; b = zeros(n, 1); b(1) = 2; b(n) = 2; b(2 : n-1) = 1; end 雅可比方法: function x = jacobi(a, b, k) n = length(b);…