Matrix Locations Winv test

advertisement
Matrix Locations Winv test
The code for\twinv.wpj tests the use of for\winv\FFTSR.FOR to invert a matrix.
The inversion derivation is in Periodic Diagonal Matrices2.doc. The code FFTSR is
tested in ../../Fourier/symmrange/Welcome.htm.
The natural dimension of a periodic array extending from –M/2 to M/2-1 is A(M/2:M/2-1). This puts the large elements near A(0) with the small elements at each end.
Periodicity means that any element less than –M/2 is moved upward by M and any
element larger than M/2-1 is moved downward by M. The FFTSR code uses Ah(M). The
elements in this code range from
Ah(1)=A(-M/2)
To
Ah(M/2+1)=A(0)
To
Ah(M)=A(M/2-1)
The routine MLOC(M,I) translates these. The equation for the inverse is
M / 2 1

n  M / 2
A1  m  n  A  n  j    j ,m
With the natural dimension this is
dimension Ainv(-M/2:M/2-1),A(-M/2:M/2-1),sum(-M/2:M2-1)
do j = -M/2,M/2-1
do ms = -M/2,M/2-1
sum(ms)=0
do n=-M/2,M/2-1
sum(ms)=sum(ms)+Ainv(ms-n)*A(n-j)
enddo
enddo
write(1,’(8e15.6)’)(sum(m),m=-M/2,M/2-1)
enddo
This becomes
dimension Ainv(M),A(M),sum(M)
do j = -M/2,M/2-1
do ms = -M/2,M/2-1
sum(MLOC(M,ms))=0
do n=-M/2,M/2-1
sum(MLOC(M,ms))=sum(MLOC(M,ms))+Ainv(MLOC(M,msn))*A(MLOC(M,n-j))
enddo
enddo
write(1,’(8e15.6)’)(sum(MLOC(M,ms)),ms=-M/2,M/2-1)
enddo
The routine MLOC is best inserted as the statement function
MLOC(M,I)=I+M/2+1
By placing this at the top of each routine that uses this, the compiler can make the trivial
replacement inside the loops to speed the code up. In this case the moves to keep –M/2 
I < M/2, need to be done before calling MLOC.
Dimension sump(-NDAT/2:NDAT/2-1),WFINV(NDAT),WF(NDAT)
…
IF(ITEST.EQ.1)THEN
OPEN(1,FILE='AinvxWF.txt')
WRITE(1,'(A)')' testing '
ENDIF
…
IF(ITEST.EQ.1)THEN
WRITE(1,'('' WpINV * Wp '')')
DO K=-NDAT/2,NDAT/2-1
DO N=-NDAT/2,NDAT/2-1
SUMP(N)=0
DO M=-NDAT/2,NDAT/2-1
KmM=K-M
IF(KmM.LT.-NDAT/2)KmM=KmM+NDAT
IF(KmM.GT.NDAT/2-1)KmM=KmM-NDAT
MmN=M-N
IF(MmN.LT.-NDAT/2)MmN=MmN+NDAT
IF(MmN.GT.NDAT/2-1)MmN=MmN-NDAT
SUMP(N)=SUMP(N)+WFINV(MLOC(NDAT,KmM)*WF(NDAT,MmN)
ENDDO
ENDDO
WRITE(1,'(''J '',8I10)')(M,M=-NDAT/2,NDAT/2-1)
WRITE(1,'(''R '',8E10.3)')(REAL(SUMP(M)),M=-NDAT/2,NDAT/2-1)
WRITE(1,'(''I '',8E10.3)')(IMAG(SUMP(M)),M=-NDAT/2,NDAT/2-1)
WRITE(1,'('' '')')
ENDDO
CLOSE(1)
CALL FSYSTEM('NOTEPAD AinvxWF')
Testing the matrix inverse
for\winv\twinv.wpj twinv.zip
Figure 1 Wf(f). The theoretical lines are for integrals to 
AinvxWF
wt
-8
-7
-6
-5
-4
-3
-2
-1
0
1
2
3
4
5
6
7
(0.3370408900911941,0.0000000000000000)
(0.4306490736957038,0.0000000000000000)
(0.5333259789535241,0.0000000000000000)
(0.6401625418294034,0.0000000000000000)
(0.7447595401877497,0.0000000000000000)
(0.8397890145601319,0.0000000000000000)
(0.9178096102413748,0.0000000000000000)
(0.9722172216669894,0.0000000000000000)
(0.9981649510710314,0.0000000000000000)
(0.9932752639408057,0.0000000000000000)
(0.9579993655608496,0.0000000000000000)
(0.8955485194420068,0.0000000000000000)
(0.8114117948988244,0.0000000000000000)
(0.7125606083384366,0.0000000000000000)
(0.6064997150602224,0.0000000000000000)
(0.5003428404188847,0.0000000000000000)
-8
-7
-6
-5
-4
-3
-2
-1
0
1
2
3
4
(15137.7502443280900000,0.0000000000000000)
(11847.3279706428100000,0.0000000000000000)
(9566.4584469288330000,0.0000000000000000)
(7969.9146434690490000,0.0000000000000000)
(6850.5880636860790000,0.0000000000000000)
(6075.3840879889300000,0.0000000000000000)
(5558.9315685905090000,0.0000000000000000)
(5247.8404029692410000,0.0000000000000000)
(5111.4205230829220000,0.0000000000000000)
(5136.5829811207170000,0.0000000000000000)
(5325.7246296187260000,0.0000000000000000)
(5697.1126695686800000,0.0000000000000000)
(6287.8563614702040000,0.0000000000000000)
wtINV
5
6
7
(7160.1499670653610000,0.0000000000000000)
(8412.2724044807220000,0.0000000000000000)
(10197.0896836559600000,0.0000000000000000)
I WfINV
-8
(2.5546498562421660,0.0000000000000000)
-7
(-2.6121220728278090,0.1994394222602848)
-6
(2.8026744485727430,-0.4133119472437266)
-5
(-3.1937176402477130,0.6601567160491324)
-4
(3.9586996250799450,-0.9690516562605254)
-3
(-5.5738898582686160,1.3921874615034540)
-2
(9.6410966503730310,-2.0250253783272990)
-1
(-23.7124244530139500,2.9010311254701700)
0
(106.3846040675835000,0.0000000000000000)
1
(-23.7124244530139500,-2.9010311254701660)
2
(9.6410966503730310,2.0250253783273000)
3
(-5.5738898582686130,-1.3921874615034550)
4
(3.9586996250799450,0.9690516562605254)
5
(-3.1937176402477090,-0.6601567160491347)
6
(2.8026744485727430,0.4133119472437258)
7
(-2.6121220728278060,-0.1994394222602846)
WpINV * Wp
J
-8
-7
-6
-5
-4
-3
-2
-1
J
0
1
2
3
4
5
6
7
R 0.100E+01-0.312E-16 0.382E-16 0.867E-17 0.733E-16-0.672E-17 0.213E-16-0.158E-16
R 0.711E-16 0.154E-16 0.416E-16-0.173E-17 0.941E-16 0.121E-16 0.486E-16 0.000E+00
I 0.949E-17-0.123E-16-0.867E-18-0.215E-16-0.155E-16 0.281E-16 0.401E-17-0.326E-16
I 0.461E-17 0.175E-16-0.152E-16-0.267E-16 0.000E+00 0.221E-16 0.347E-17 0.278E-16
J
-8
-7
-6
-5
-4
-3
-2
J
0
1
2
3
4
5
6
R -0.312E-16 0.100E+01-0.343E-16 0.425E-16 0.139E-16 0.725E-16-0.510E-17
R -0.125E-16 0.736E-16 0.144E-16 0.416E-16-0.781E-17 0.989E-16 0.173E-16
I 0.265E-16 0.944E-17-0.109E-16 0.133E-17-0.219E-16-0.154E-16 0.283E-16
I -0.323E-16 0.428E-17 0.173E-16-0.152E-16-0.260E-16 0.239E-17 0.191E-16
J
J
R
R
I
I
-8
-7
0
1
0.538E-16-0.239E-16
0.241E-16-0.138E-16
0.325E-17 0.255E-16
0.404E-17-0.325E-16
-6
-5
-4
-3
-2
-1
2
3
4
5
6
7
0.100E+01-0.348E-16 0.369E-16 0.548E-17 0.726E-16-0.358E-17
0.714E-16 0.132E-16 0.459E-16-0.932E-17 0.989E-16 0.694E-17
0.944E-17-0.108E-16-0.176E-17-0.219E-16-0.151E-16 0.282E-16
0.428E-17 0.172E-16-0.144E-16-0.262E-16 0.260E-17 0.191E-16
J
-8
-7
-6
J
0
1
2
R 0.520E-17 0.609E-16-0.442E-16
R -0.331E-17 0.242E-16-0.137E-16
I 0.204E-16 0.446E-17 0.262E-16
I 0.287E-16 0.397E-17-0.324E-16
J
-8
-7
J
0
1
R 0.954E-16 0.113E-16
R 0.699E-16-0.445E-17
I 0.434E-18 0.208E-16
I -0.146E-16 0.286E-16
-5
-4
-3
-2
-1
3
4
5
6
7
0.100E+01-0.427E-16 0.463E-16 0.840E-17 0.724E-16
0.735E-16 0.153E-16 0.455E-16-0.104E-16 0.971E-16
0.944E-17-0.135E-16 0.698E-18-0.214E-16-0.150E-16
0.426E-17 0.173E-16-0.139E-16-0.252E-16-0.173E-17
-6
-5
2
3
0.532E-16-0.413E-16
0.207E-16-0.129E-16
0.213E-17 0.254E-16
0.369E-17-0.325E-16
-4
-3
-2
-1
4
5
6
7
0.100E+01-0.219E-16 0.371E-16 0.808E-17
0.714E-16 0.141E-16 0.442E-16-0.694E-17
0.945E-17-0.117E-16 0.407E-18-0.204E-16
0.404E-17 0.175E-16-0.139E-16-0.260E-16
J
-8
-7
-6
-5
-4
J
0
1
2
3
4
R -0.520E-17 0.948E-16 0.802E-17 0.576E-16-0.310E-16
R 0.146E-16 0.711E-16-0.390E-17 0.222E-16-0.137E-16
I -0.259E-16 0.840E-18 0.202E-16 0.289E-17 0.264E-16
I -0.219E-16-0.149E-16 0.277E-16 0.423E-17-0.323E-16
J
-8
-7
-6
-5
J
0
1
2
3
R 0.416E-16-0.455E-17 0.971E-16 0.157E-16
R 0.443E-16 0.155E-16 0.745E-16-0.520E-17
I -0.152E-16-0.255E-16 0.176E-18 0.197E-16
I 0.264E-18-0.203E-16-0.151E-16 0.275E-16
J
-8
-7
-1
7
0.211E-16
0.416E-16
0.420E-17
0.694E-17
-6
-5
-3
-2
-1
5
6
7
0.100E+01-0.376E-16 0.361E-16
0.712E-16 0.139E-16 0.451E-16
0.942E-17-0.117E-16 0.861E-18
0.412E-17 0.173E-16-0.156E-16
-4
-3
4
5
0.498E-16-0.240E-16
0.194E-16-0.155E-16
0.286E-17 0.275E-16
0.434E-17-0.325E-16
-4
-3
-2
-1
6
7
0.100E+01-0.386E-16
0.711E-16 0.104E-16
0.944E-17-0.125E-16
0.434E-17 0.169E-16
-2
-1
J
0
1
2
3
4
R 0.867E-17 0.437E-16-0.564E-17 0.941E-16 0.927E-17
R -0.343E-16 0.415E-16 0.110E-16 0.776E-16-0.493E-17
I 0.173E-16-0.155E-16-0.258E-16-0.312E-18 0.200E-16
I -0.117E-16 0.725E-18-0.213E-16-0.143E-16 0.282E-16
J
J
R
R
I
I
5
6
0.572E-16-0.324E-16
0.188E-16-0.147E-16
0.324E-17 0.270E-16
0.377E-17-0.324E-16
-8
-7
-6
-5
-4
-3
0
1
2
3
4
5
0.729E-16 0.159E-16 0.415E-16-0.705E-17 0.952E-16 0.141E-16
0.100E+01-0.305E-16 0.353E-16 0.949E-17 0.719E-16-0.575E-17
0.477E-17 0.172E-16-0.149E-16-0.256E-16 0.108E-18 0.205E-16
0.942E-17-0.118E-16-0.596E-18-0.208E-16-0.147E-16 0.285E-16
-2
-1
6
7
0.513E-16-0.287E-16
0.165E-16-0.208E-16
0.451E-17 0.275E-16
0.417E-17-0.321E-16
J
-8
-7
-6
-5
-4
-3
-2
J
0
1
2
3
4
5
6
R -0.113E-16 0.748E-16 0.155E-16 0.420E-16-0.377E-17 0.907E-16 0.919E-17
R -0.246E-16 0.100E+01-0.395E-16 0.286E-16 0.970E-17 0.756E-16-0.434E-17
I -0.325E-16 0.423E-17 0.173E-16-0.151E-16-0.262E-16-0.271E-19 0.199E-16
I 0.267E-16 0.945E-17-0.113E-16-0.129E-18-0.211E-16-0.138E-16 0.276E-16
J
J
R
R
I
I
-8
-7
0
1
0.252E-16-0.132E-16
0.569E-16-0.258E-16
0.520E-17-0.329E-16
0.417E-17 0.280E-16
7
0.100E+01
0.763E-16
0.942E-17
0.477E-17
-1
7
0.626E-16
0.208E-16
0.364E-17
0.434E-17
-6
-5
-4
-3
-2
-1
2
3
4
5
6
7
0.733E-16 0.130E-16 0.428E-16-0.615E-17 0.941E-16 0.101E-16
0.100E+01-0.319E-16 0.347E-16 0.412E-17 0.781E-16-0.694E-17
0.420E-17 0.175E-16-0.153E-16-0.257E-16-0.136E-19 0.205E-16
0.943E-17-0.133E-16-0.149E-18-0.209E-16-0.151E-16 0.278E-16
J
-8
-7
-6
-5
-4
-3
-2
-1
J
0
1
2
3
4
5
6
7
R -0.434E-17 0.258E-16-0.116E-16 0.711E-16 0.153E-16 0.422E-16-0.575E-17 0.954E-16
R 0.949E-17 0.560E-16-0.417E-16 0.100E+01-0.220E-16 0.390E-16 0.694E-17 0.694E-16
I 0.273E-16 0.455E-17-0.323E-16 0.412E-17 0.175E-16-0.149E-16-0.257E-16-0.136E-19
I 0.200E-16 0.343E-17 0.278E-16 0.942E-17-0.112E-16 0.108E-18-0.215E-16-0.139E-16
J
-8
-7
J
0
1
R 0.798E-16-0.282E-17
R 0.928E-16 0.932E-17
I -0.139E-16 0.280E-16
I -0.366E-18 0.213E-16
-6
-5
2
3
0.229E-16-0.140E-16
0.605E-16-0.478E-16
0.445E-17-0.327E-16
0.366E-17 0.281E-16
J
-8
-7
-6
J
0
1
2
R 0.173E-16 0.768E-16-0.347E-17
R -0.314E-17 0.925E-16 0.126E-16
I -0.208E-16-0.147E-16 0.280E-16
I -0.255E-16 0.556E-18 0.209E-16
-4
-3
-2
-1
4
5
6
7
0.725E-16 0.145E-16 0.422E-16-0.672E-17
0.100E+01-0.455E-16 0.312E-16 0.694E-17
0.428E-17 0.177E-16-0.147E-16-0.259E-16
0.946E-17-0.111E-16-0.867E-18-0.226E-16
-5
-4
3
4
0.195E-16-0.121E-16
0.551E-16-0.284E-16
0.379E-17-0.325E-16
0.336E-17 0.272E-16
J
-8
-7
-6
-5
J
0
1
2
3
R 0.278E-16 0.520E-17 0.737E-16-0.867E-18
R 0.416E-16-0.130E-17 0.928E-16 0.130E-16
I -0.173E-17-0.226E-16-0.147E-16 0.282E-16
I -0.152E-16-0.260E-16 0.542E-19 0.209E-16
-3
-2
-1
5
6
7
0.732E-16 0.144E-16 0.422E-16
0.100E+01-0.382E-16 0.416E-16
0.434E-17 0.173E-16-0.154E-16
0.943E-17-0.126E-16 0.000E+00
-4
-3
4
5
0.204E-16-0.132E-16
0.633E-16-0.252E-16
0.423E-17-0.326E-16
0.304E-17 0.254E-16
J
-8
-7
-6
-5
-4
J
0
1
2
3
4
R 0.000E+00 0.278E-16 0.104E-16 0.677E-16-0.173E-17
R 0.121E-16 0.416E-16-0.347E-17 0.937E-16 0.104E-16
I -0.139E-16 0.173E-17-0.226E-16-0.143E-16 0.282E-16
I 0.165E-16-0.147E-16-0.265E-16 0.434E-18 0.199E-16
-2
-1
6
7
0.711E-16 0.132E-16
0.100E+01-0.278E-16
0.407E-17 0.175E-16
0.943E-17-0.139E-16
-3
-2
5
6
0.208E-16-0.113E-16
0.625E-16-0.278E-16
0.455E-17-0.325E-16
0.347E-17 0.243E-16
-1
7
0.729E-16
0.100E+01
0.461E-17
0.949E-17
Minimum size
The inverse depends on finding 1/wt(i). This is a problem for wt  0. With the
maximum set at 1, the test wtsize.txt made this minimum 10-8. This produced Wf-1Wf
errors on the order of 10-9 which seems a reasonable compromise between small size and
accuracy.
This routine also indicates that all arrays can be equivalenced. – Beware that needed
ones must be saved before any more fft calls.
for\winv\winv.for
EQUIVALENCE (wt(1),wtinv(1)),(wt(1),Wfinv(1)),(wt(1),DAT(1))
Download