刚入门两个月,还望诸位多多指教!
带状矩阵的高斯消去法求解这个阶数为10x10,上下带宽为3的矩阵,结果一直不对。解应为3.14
调试之后发现 在第三次消元,即k=3,i=5时,martix(i,k)的值并没有消为0,而是等于了0.5,
看了本次循环的matrix值没问题,求出来的factor也没问题,但是就是结果并不为0
程序算法用其他题目验证过,可以得出正确的解,如有问题,希望指点迷津!
谢谢大家!
(这个矩阵是用二进制文件给出)
代码如下
[Fortran] 纯文本查看 复制代码 ! Gaussian elimination
DO k = 1, n
! Pivot row operations
m1=k+p
if(k+p>n)then
m1=n
end if
DO i = k + 1, m1
factor = matrix(i, k) / matrix(k, k)
m2=k+q
if(k+q>n)then
m2=n
end if
if(i==5 .and. k==3)then
print*, '第三次消元:',Matrix(i,k), Matrix(k,k),factor !???????????
end if
matrix(i, k:m2) = matrix(i, k:m2) - (factor * matrix(k, k:m2))
matrix(i, n+1) = matrix(i, n+1) - factor * matrix(k,n+1)
END DO
END DO
! Back substitution
DO i = n, 1, -1
x(i) = matrix(i, n + 1) / matrix(i, i)
DO j = i + 1, n
x(i) = x(i) - matrix(i, j) * x(j) / matrix(i, i)
END DO
END DO
1.10473882E+09 1.09041626E+09 1.07034445E+09 1.09137050E+09 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 1.12589274E+09
1.08574170E+09 1.10226829E+09 1.08266099E+09 1.07726080E+09 1.07692954E+09 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 1.12422080E+09
1.09137574E+09 1.07552026E+09 1.10270093E+09 1.07513434E+09 1.07338950E+09 1.08925440E+09 0.00000000 0.00000000 0.00000000 0.00000000 1.12442470E+09
1.09040154E+09 1.07663590E+09 1.07586419E+09 1.10339610E+09 1.06927072E+09 1.07365792E+09 1.07875405E+09 0.00000000 0.00000000 0.00000000 1.12499814E+09
0.00000000 1.08633523E+09 1.08290842E+09 1.06578106E+09 1.10414003E+09 1.07429133E+09 1.08411226E+09 1.08068339E+09 0.00000000 0.00000000 1.12585690E+09
0.00000000 0.00000000 1.08739635E+09 1.06885965E+09 1.08767117E+09 1.10633318E+09 1.08567258E+09 1.09240960E+09 1.06609978E+09 0.00000000 1.12764890E+09
0.00000000 0.00000000 0.00000000 1.08264422E+09 1.07120006E+09 1.09044147E+09 1.10873408E+09 1.06734131E+09 1.09085773E+09 1.09203738E+09 1.12957837E+09
0.00000000 0.00000000 0.00000000 0.00000000 1.09149107E+09 1.08395072E+09 1.09138099E+09 1.10669389E+09 1.08961510E+09 1.08007936E+09 1.12728934E+09
0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 1.08056602E+09 1.07280230E+09 1.08680704E+09 1.10683699E+09 1.10590272E+09 1.12566963E+09
|