Bonjour,
comme j ai lu , si j ai A(1,M) et B(1,M) deux matrices comples, alors A*B=FFT^-1(FFT(A).FFT(B))
J ai essaye' de programmer cette formule en calculant A*B par deux facons, mais j ai pas obtenu la meme reponse, alors ou est l erreur?
Voila mon code, laissez tomber les sous routine longue, je doutes que l erreur se trouve dans le programme
merci

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
 
      program test
      parameter(M=2**1)
      integer i,j
      complex A(2*m,2*m),B(4*m,4*m),C(4*m,4*m),D(4*m,4*m)
      complex AA(-m:m-1,-m:m-1),BB(-m:m-1,-m:m-1),CC(-m:m-1,-m:m-1)
       do i=-m,m-1
          do j=-m,m-1
             if((i.ne.0).and.(j.ne.0)) then
                AA(i,j)=cmplx(1.,2.*j)
             else
                AA(i,j)=cmplx(0.,0.)
             endif
          enddo
      enddo
 
!      print*,"A=",AA
 
        do i=1,2*M
           do j=1,2*M
                  A(i,j)=AA(i-M-1,j-M-1)
           enddo
        enddo
 
!      print*,'a=',A
 
 
!      Call AhFFT(30.d0,M,A,C)
      call Ah(30.d0,M,AA,CC)
 
      do i=-m,M-1
         do j=-m,m-1
            print*,'A*B',i,j,',',CC(i,j)
         enddo
      enddo
 
      call AhFFT(30.d0,M,A,C)
 
      do i=1,4*M
         do j=1,4*M
            print*,'AB',i,j,',',C(i,j)
         enddo
      enddo
      end
 
        subroutine AhFFT(s,MM,phi,psi)
        integer i,j,j1,j2
        complex phii(4*MM,4*MM),phi(2*MM,2*MM),
     &  psi(4*MM,4*MM),G(4*MM,4*MM),
     &               L(4*MM,4*MM)
        double precision h,s
        parameter(pi=3.141592653d0)
        h=s/real(MM)
        do j1=1,4*MM
           do j2=1,4*MM
             if((j1.ne.(2*MM+1)).and.(j2.ne.(2*MM+1))) then
                 G(j1,j2)=1./(pi*h*cmplx(real(j1)-real(2.*MM)-1.d0,
     &                         real(j2)-real(2.*MM)-1.d0))
             else
                 G(j1,j2)=cmplx(0.,0.)
             endif
           enddo
        enddo
!       print*,'G=',G
        do i=1,4*MM
           do j=1,4*MM
              if((i.le.2*MM).and.(j.le.2*MM)) then
                 phii(i,j)=phi(i,j)
              else
                 phii(i,j)=cmplx(0.,0.)
              endif
            enddo
        enddo
!        print*,'phi=',i,j,phii
        Call fft2d(G,2000,4*MM)
        Call fft2d(phii,2000,4*MM)
        do i=1,4*MM
           do j=1,4*MM
              L(i,j)=G(i,j)*phii(i,j)
           enddo
        enddo
        Call ifft2d(L,2000,4*MM)
 
        do i=1,4*MM
           do j=1,4*MM
              psi(i,j)=L(i,j)*h**2
           enddo
        enddo
 
 
        return
        end
 
        subroutine Ah(s,MM,phi,psi)
        integer i,j,j1,j2
        complex phi(-MM:MM-1,-MM:MM-1),psi(-MM:MM-1,-MM:MM-1)
C&               ii
        double precision h,s
C        parameter(ii=(0.,1.))
        parameter(pi=3.141592653d0)
C        ii=cmplx(0.,1.)
        h=2.*s/real(MM)
        do j1=-MM,MM-1
           do j2=-MM,MM-1
              psi(j1,j2)=cmplx(0.,0.)
              do l1=-MM,MM-1
                 do l2=-MM,MM-1
                    if((l1.ne.j1).and.(l2.ne.j2)) then
C                            psi(j1,j2)=cmplx(0.,0.)
C                        else
                       psi(j1,j2)=psi(j1,j2)+1./(pi*h*
C&                          (real(j1)-real(l1)+ii*(real(j2)-real(l2))))
     &                  cmplx(real(j1)-real(l1),real(j2)-real(l2)))
     &                  *phi(l1,l2)
                    endif
                 enddo
              enddo
              psi(j1,j2)=psi(j1,j2)*h**2
           enddo
        enddo
        return
        end
 
      subroutine fft2d(field, m, n)
      integer m, n, i ,j
      complex field(n, n)
      complex xlong(2000)
      do i = 1,n
         do j = 1,n 
            xlong(j) = field(i,j)
         end do
         call fft1d(xlong, m, n)
         do j = 1,n 
            field(i,j) = xlong(j)
         end do
      end do
      do j = 1,n
         call fft1d(field(1,j), m, n)
      end do
      return
      end
 
      subroutine fft1d(z,m,n)
      complex z(*)
      complex zt,wt,w(2**15)
      double precision p
      integer n,m,m2
      save w, m2
      data m2 /-1/
 
      if (m .eq. 0) then
         return
      endif
      if (m .ne. m2) then
         p = 6.283185307179586d0/n
         do k = 1,n/2
            w(k) = cmplx(cos(p*(k-1)),sin(p*(k-1)))
            w(k+n/2) = conjg(w(k))
         enddo
         m2 = m
      endif
      ks = 1
      n2 = n
      kn2 = ks*n
      ie = 1
      ia1 = n/2 + 1
      do k = 1,m
         n1 = n2
         kn1 = kn2
         n2 = n2/2
         kn2 = kn2/2
         ia= ia1
         kj = 1
         do j = 1,n2
            wt = w(ia)
            ia = ia + ie
            ki = kj
            do i = j,n,n1
               kl = ki + kn2
               zt = z(ki) - z(kl)
               z(ki) = z(ki) + z(kl)
               z(kl) = wt*zt
               ki = ki+kn1
            end do
            kj = kj+ks
         end do
         ie = ie+ie
      end do
 
      j = 1
      n1 = n - 1
      ki = 1
      kj = 1
      do i=1,n1
         if(i.lt.j) then
            zt = z(kj)
            z(kj) = z(ki)
            z(ki) = zt
         endif
         k = n/2
         do while (k.lt.j)
            j = j - k
            k = k/2
         end do
         j = j + k
         kj = ks*(j-1) + 1
         ki = ki + ks
      end do
 
      return
      end
 
      subroutine ifft2d(field, m, n)
      integer m, n, i ,j
      complex field(n, n)
      complex xlong(2000)
      do i = 1,n
         do j = 1,n 
            xlong(j) = field(i,j)
         end do
         call ifft1d(xlong, m, n)
         do j = 1,n 
            field(i,j) = xlong(j)
         end do
      end do
      do j = 1,n
         call ifft1d(field(1,j), m, n)
      end do
      return
      end
 
      subroutine ifft1d(z, m, n)
      complex z(*)
      complex zt,wt,w(2**15)
      double precision p
      integer n,m,m2
      save w, m2
      data m2 /-1/
 
      if (m .eq. 0) then
         return
      endif
      if (m .ne. m2) then 
         p = 6.283185307179586d0/n
         do k = 1,n/2
 
            w(k) = cmplx(cos(p*(k-1)),sin(p*(k-1)))
 
            w(k+n/2) = conjg(w(k))
         end do
         m2 = m
      end if
 
      ks = 1
      nlast = n
      n2 = n
      kn2 = ks*n
      ie = 1
      do k = 1,m
         n1 = n2
         kn1 = kn2
         n2 = n2/2
         kn2 = kn2/2
         ia = 1
         kj = 1
         do j = 1,n2
            wt = w(ia)
            ia = ia + ie
            ki = kj
            do i = j,n,n1
               kl = ki + kn2
               zt = z(ki) - z(kl)
               z(ki) = z(ki) + z(kl)
               z(kl) = wt*zt
               ki = ki+kn1
            end do
            kj = kj+ks
         end do
         ie = ie+ie
      end do
      ki = 1
      do i = 1,n
         z(ki) = z(ki)/float(n)
         ki = ki+ks
      end do
      j = 1
      n1 = n - 1
      ki = 1
      kj = 1
      do i=1,n1
         if(i.lt.j) then
            zt = z(kj)
            z(kj) = z(ki)
            z(ki) = zt
         endif
         k = n/2
         do while (k.lt.j)
            j = j - k
            k = k/2
         end do
         j = j + k
         kj = ks*(j-1) + 1
         ki = ki + ks
      end do
      return
      end