[Fortran] 纯文本查看 复制代码
PROGRAM MAIN
USE MKL95_PRECISION
USE MKL95_LAPACK
IMPLICIT NONE
INTEGER :: I, J, N, INFO
! INTEGER,ALLOCATABLE:: IPIV(:)
COMPLEX(8), ALLOCATABLE :: A(:,:), B(:,:), IPIV(:)
N = 3
ALLOCATE( IPIV(N) )
ALLOCATE( A(N,N), B(N,1) )
A = 0.0
Open (5, File='A.TXT', Status='OLD') ! INPUT FILE
DO J=1,N
DO I=1,N
READ(5,*) A(I,J)
ENDDO
ENDDO
B = 0.0
Open (6, File='B.TXT', Status='OLD') ! INPUT FILE
DO I=1,N
READ(6,*) B(I,1)
ENDDO
WRITE(*,*)
WRITE(*,*)'Matrix A : '
DO I=1,N;
WRITE(*,*) (A(I,:));
ENDDO
WRITE(*,*)
WRITE(*,*)'Matrix B : '
DO I=1,N;
WRITE(*,*) (B(I,1));
ENDDO
CALL ZGETRS( 'N', N, 1, A, N, IPIV, B, N, INFO )
! CALL GETRS(A, IPIV, B, 'N', INFO)
WRITE(*,*)
WRITE(*,*)'Matrix B : '
DO I=1,N;
WRITE(*,*) (B(I,1));
ENDDO
WRITE(*,*) INFO
END PROGRAM MAIN
[Fortran] 纯文本查看 复制代码
program main
use f95_precision
use lapack95
implicit none
integer :: i, j, n, info
integer,allocatable:: ipiv(:)!// ipiv 为整数
complex(8), allocatable :: a(:,:), b(:,:)
n = 3
allocate( ipiv(n) )
allocate( a(n,n), b(n,1) )
a = 0.0
open (5, file='a.txt', status='old') ! input file
do j=1,n
do i=1,n
read(5,*) a(j,i)!//a转置
enddo
enddo
!a = transpose(a)!//或者这样转置
b = 0.0
open (6, file='b.txt', status='old') ! input file
do i=1,n
read(6,*) b(i,1)
enddo
write(*,*)
write(*,*)'matrix a : '
do i=1,n;
write(*,*) (a(i,:));
enddo
write(*,*)
write(*,*)'matrix b : '
do i=1,n;
write(*,*) (b(i,1));
enddo
!call zgetrs( 'n', n, 1, a, n, ipiv, b, n, info )
call getrf(a,ipiv,info)!//先 getrf
call getrs(a,ipiv,b,'n',info) !//后 getrs
write(*,*)
write(*,*)'matrix b : '
do i=1,n;
write(*,*) (b(i,1));
enddo
write(*,*) info
end program main