[求助]用matlab编写的sor法?
刚接触matlab编程不久,编了个sor法的程序
如下:
A=[4 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1;
-2 6 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1;
-1 -2 6 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1;
-1 0 -2 6 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1;
-1 0 0 -2 6 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1;
-1 0 0 0 -2 6 1 0 0 0 0 0 0 0 0 0 0 0 0 1;
-1 0 0 0 0 -2 6 1 0 0 0 0 0 0 0 0 0 0 0 1;
-1 0 0 0 0 0 -2 6 1 0 0 0 0 0 0 0 0 0 0 1;
-1 0 0 0 0 0 0 -2 6 1 0 0 0 0 0 0 0 0 0 1;
-1 0 0 0 0 0 0 0 -2 6 1 0 0 0 0 0 0 0 0 1;
-1 0 0 0 0 0 0 0 0 -2 6 1 0 0 0 0 0 0 0 1;
-1 0 0 0 0 0 0 0 0 0 -2 6 1 0 0 0 0 0 0 1;
-1 0 0 0 0 0 0 0 0 0 0 -2 6 1 0 0 0 0 0 1;
-1 0 0 0 0 0 0 0 0 0 0 0 -2 6 1 0 0 0 0 1;
-1 0 0 0 0 0 0 0 0 0 0 0 0 -2 6 1 0 0 0 1;
-1 0 0 0 0 0 0 0 0 0 0 0 0 0 -2 6 1 0 0 1;
-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -2 6 1 0 1;
-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -2 6 1 1;
-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -2 6 1;
-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -2 4];
B=[82 -32 -14 -14 -14 -14 -14 -14 -14 -14 -14 -14 -14 -14 -14 -14 -14 -14 -15 -18]';
x=ones(20,1);
rept=10000;
p=1.000001;
while p>=0.000001
while rept>0
p=0;
for i=1:20
s=B(i);
for k=1:20
if k~=i
s=s+A(i,k)*x(k);
end
end
t=(1-1.87)*x(i)+1.87/A(i,i)*(B(i)-s);
if abs(x(i)-t)>p
p=abs(x(i)-t);
end
x(i)=t;
end
rept=rept-1;
end
end
x
但运行出来结果全是NaN
帮帮忙啊