是这样的吗?
format rat
n=8 %n=20
A=zeros(n)+diag(3*ones(n,1),0)+diag(-1/2*ones(n-1,1),1)+diag(-1/4*ones(n-2,1),2)+diag(-1/2*ones(n-1,1),-1)+diag(-1/4*ones(n-2,1),-2)
%b=ones(n,1)
b=[1:n]'
x=A\b
结果:
n =
8
A =
3 -1/2 -1/4 0 0 0 0 0
-1/2 3 -1/2 -1/4 0 0 0 0
-1/4 -1/2 3 -1/2 -1/4 0 0 0
0 -1/4 -1/2 3 -1/2 -1/4 0 0
0 0 -1/4 -1/2 3 -1/2 -1/4 0
0 0 0 -1/4 -1/2 3 -1/2 -1/4
0 0 0 0 -1/4 -1/2 3 -1/2
0 0 0 0 0 -1/4 -1/2 3
b =
1
2
3
4
5
6
7
8
x =
878/1217
175/131
2343/1180
1685/644
1927/602
2143/581
416/109
1426/395
再用雅可比迭代和高斯-塞德尔迭代法求解?