!lfsrg和后面的 lfirg都是利用lu分解系数矩阵来进行线性方程组的求解 !lfirg因为调用lfsrg,每一步都进行解的精度改进,因而计算时间更长但精度更高 ! !exmple !矩阵求逆 !当系数矩阵well-conditioned时,lftrg is sed rather than lfcrg ! declare variables parameter (ipath=1, lda=3, ldfac=3, n=3) integer i, ipvt(n), j real a(lda,lda), ainv(lda,lda), fac(ldfac,ldfac), rj(n) ! ! set val es for a ! a = ( 1.0 3.0 3.0) ! ( 1.0 3.0 4.0) ! ( 1.0 4.0 3.0) ! data a1.0, 1.0, 1.0, 3.0, 3.0, 4.0, 3.0, 4.0, 3.0 ! !进行lu分解 call lftrg (n, a, lda, fac, ldfac, ipvt) ! ! set p the col mns of the identity ! matrix one at a time in rj call sset (n, 0.0, rj, 1) ! do j=1, n rj(j) = 1.0 ! ! rj(j)-ainv(j) ! rj(j)是单位矩阵的第j列 ! 求解 a*rj(:)=ainv(1,:) call lfsrg (n, fac, ldfac, ipvt, rj, ipath, ainv(1,j)) rj(j) = 0.0 end do ! print res lts call wrrrn ( ainv , n, n, ainv, lda, 0) end !