!************************************************************************** !* This program tests the subroutine CGESV which computes the solution * !* to a complex system of linear equations by LU factorization. * !* A * X = B, * !* where A is an N-by-N matrix and X and B are N-by-NRHS matrices. * !* ---------------------------------------------------------------------- * !* SAMPLE RUN: * !* (Solve the complex linear system: * !* (2,0) (-1,0) ( 1,0) (5,0) (-1,0) (1,0) (2,0) * !* (1,0) ( 5,0) (-2,0) X = (1,0) ( 2,0) (3,0) (4,0) * !* (3,0) (-2,0) ( 3,0) (3,0) ( 7.556,0) (4,0) (4,0) ) * !* * !* Linear system matrix: * !* 2.00000 0.00000 -1.00000 0.00000 1.00000 0.00000 * !* 1.00000 0.00000 5.00000 0.00000 -2.00000 0.00000 * !* 3.00000 0.00000 -2.00000 0.00000 3.00000 0.00000 * !* Second member: * !* 5.00000 0.00000 -1.00000 0.00000 1.00000 0.00000 2.00000 0.00000 * !* 1.00000 0.00000 2.00000 0.00000 3.00000 0.00000 4.00000 0.00000 * !* 3.00000 0.00000 7.55600 0.00000 4.00000 0.00000 4.00000 0.00000 * !* Solution Matrix X: * !* 3.35714 0.00000 -2.26200 0.00000 0.14286 0.00000 1.00000 0.00000 * !*-1.92857 0.00000 3.77000 0.00000 1.42857 0.00000 1.00000 0.00000 * !*-3.64286 0.00000 7.29400 0.00000 2.14286 0.00000 1.00000 0.00000 * !* ERROR CODE (must be zero): 0 * !* ---------------------------------------------------------------------- * !* Ref.: LAPACK Fortran 77 Library, University of Tennessee, University * !* of California Berkeley, NAG Ltd., Courant Institute, Argonne * !* National Lab, and Rice University, March 31, 1993. * !* * !* Fortran 90 Test Program By J.-P. Moreau, Paris. * !************************************************************************** !Note: link with F90 modules Lapack1, Lapack2. PROGRAM TEST_CGESV USE LAPACK1, ONLY : CGESV PARAMETER(ISIZE1=25,ISIZE2=5) COMPLEX A(ISIZE1,ISIZE1), B(ISIZE1,ISIZE2) INTEGER IPIV(ISIZE1) N=3 !number of rows of matrix C NRHS=4 !number of columns of matrix B LDC=ISIZE1 LDB=ISIZE1 ! define complex linear system (here real coefficients) A(1,1)=2.d0; A(1,2)=-1.d0; A(1,3)= 1.d0 A(2,1)=1.d0; A(2,2)= 5.d0; A(2,3)=-2.d0 A(3,1)=3.d0; A(3,2)=-2.d0; A(3,3)= 3.d0 ! define second members (here also real coefficients) B(1,1)=5.d0; B(1,2)=-1.d0; B(1,3)=1.d0; B(1,4)=2.d0 B(2,1)=1.d0; B(2,2)= 2.d0; B(2,3)=3.d0; B(2,4)=4.d0 B(3,1)=3.d0; B(3,2)= 7.556d0; B(3,3)=4.d0; B(3,4)=4.d0 print *, ' Linear System Matrix :' write(*,10) ((A(i,j),j=1,N), i=1,N) print *, ' Second members:' write(*,15) ((B(i,j),j=1,NRHS), i=1,N) CALL CGESV(N,NRHS,A,LDC,IPIV,B,LDB,INFO) !see Lapack1 module print *, ' Solution Matrix X:' write(*,15) ((B(i,j),j=1,NRHS), i=1,N) print *, 'ERROR CODE (must be zero): ', INFO 10 format(6F9.5) 15 format(8F9.5) stop END !end of file Tcgesv.f90