Je comprends pas:
Avec aln.90:
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
module aln
  implicit none   !pas ds contains
contains
 
  function prv2v(r,v)
    ! produit reel*vecteur -> vecteur
    implicit none
    real, intent(in) :: r
    real, dimension(:), intent(in) :: v
    real, dimension(size(v)) :: prv2v
    integer i
    do i=1,size(v)
       prv2v(i)=r*v(i)
    end do
  end function prv2v
  ! comparer avec r*v ou v*r
 
  function pvv2r (u,v)
    ! produit vecteur*vecteur -> reel
    ! size(v) == size(u)
    implicit none
    real, dimension(:), intent(in) :: u,v
    real :: pvv2r
    integer i
    pvv2r = 0
    do i=1,size(u)
       pvv2r = pvv2r + u(i)*v(i)
    end do
  end function pvv2r
  ! comparer avec sum(u*v)
 
  !   function pmv2v (m,v)
  !     ! produit matrice*vecteur -> vecteur
  !     ! size(m,2) == size(v)
  !     implicit none
  !     real, intent(in), dimension(:,:) :: m
  !     real, intent(in), dimension(size(m,2)) :: v
  !     real, dimension(size(m,1)) :: pmv2v
  !     integer i 
  !   end function pmv2v
 
  !   function pvm2v(v,m)
  !     ! produit vecteur(ligne)*matrice -> vecteur(ligne)
  !     ! size(v) == size(m,1)
  !     implicit none
  !     real, intent(in), dimension(:) :: v
  !     real, intent(in), dimension(size(v),:) :: m
  !     real, dimension(size(m,2)) :: pvm2v
  !     integer i
  !   end function pvm2v
 
  !   function pmm2m (a,b)
  !     ! produit matrice*matrice -> matrice
  !     ! size(a,2) == size(b,1)
  !     implicit none
  !     real, intent(in), dimension(:,:) :: a,b
  !     real, dimension(size(a,1),size(b,2)) :: pmm2m
  !     integer i k
  !   end function pmm2m
 
 
  subroutine aelu(a)
    !<a href="http://ima.epfl.ch/asn/exos02/tableaux_cours2002.pdf" target="_blank">http://ima.epfl.ch/asn/exos02/tableaux_cours2002.pdf</a>
    implicit none
    real, intent(inout), dimension(:,:) :: a
    integer :: i,n,j
    real r
    n=size(a,1)  !hyp : a carree
    print  *, "in aelu"
    do i=1,n-1
       r=1.0/a(i,i)
       a(i+1:,i)= r*a(i+1:,i)
       !      a(i+1:n,i+1:n)= a(i+1:n,i+1:n)-a(i+1:n,i)*a(i,i+1:n)
       do j=i+1, n
          a(i+1:,j)=a(i+1:,j)+a(i+1:,i)*a(i,j)
       end do
    end  do
  end subroutine aelu
 
 
 
 
   function somm(horiz,vert,min,max)  !!!type
    real ,intent (inout),dimension(:) :: horiz,vert
    integer, intent(in) :: min, max
    real ::  prodScalr=0.
    real  :: somm
    integer :: dim,k
 
    do k=min,max
       prodScalr=prodScalr+horiz(k)*vert(k)   !peut etre system-implementé
    end do
    somm=prodScalr
!RETURN  
  end  function somm
 
 
 
  subroutine luxeb(lu,b)
    real, intent(in), dimension(:,:) :: lu
    real ,intent (inout),dimension(:) :: b
    real , allocatable, dimension(:) :: y !!
    real, allocatable, dimension(:,:) :: l
    real,  allocatable, dimension(:,:) :: u
!    real  :: somm
    integer ::dimi,i,j,descente,montee, k
    real :: s
    dimi=size(lu,1)
 
 
    do descente=1,dimi
       !   y(descente)=(b(descente)-l(descente,k)*y(k))/l(descente,descente)
 
      ! s=somm(lu(descente,:),y(:),1,descente-1)
s=somm(lu(descente,:),y(:),1,descente-1)
       y(descente)=b(descente)-s
       !  sigma  l(descente,k)*y(k)
    end do
 
    do montee=dimi,1
 
    end do
 
 
  end   subroutine  luxeb
 
  subroutine  afficheDiffM(M,N)
    real, intent(inout), dimension(:,:) :: M,N
    integer ::dimi,dimj,i,j
    dimi=size(M,1)
    dimj=size(M,2)
    do i=1,dimi
       print *, (M(i,j)-M(i,j), j=1,dimj)
    end do
 
 
  end  subroutine  afficheDiffM
 
 
 
 
 
  subroutine  afficheM(MM)
 
 
    real, intent(in), dimension(:,:) :: MM
    integer ::dimi,dimj,i,j
    dimi=size(MM,1)
    dimj=size(MM,2)
    do i=1,dimi
       print *, (MM(i,j), j=1,dimj)
    end do
  end  subroutine  afficheM
 
 
 
 
  subroutine getL(a)
    real, intent(inout), dimension(:,:) :: a
    integer ::dim,i,j
    dim=size(a,1)
 
    do j=1,dim  !ds cet ordre
       do i=1,j-1
          a(i,j)=0
       end do
       a(i,i)=1 
    end do
  end  subroutine getL
 
  subroutine getU(a)
    real, intent(inout), dimension(:,:) :: a
    integer ::dim,i,j
    dim=size(a,1)
 
    do j=1,dim  !ds cet ordre
       a(j,j)=1
       do i=j+1,dim
          a(i,j)=0
       end do
 
    end do
  end  subroutine getU
 
  subroutine  afficheL(a)
    real, intent(inout), dimension(:,:) :: a
    integer ::dim,i,j
    dim=size(a,1)
    do i=1,dim !cet ordre car affichage par lignes
 
       !& edit descriptor evite saut de ligne          
       !:mieux vaut etre imperatif que conditionnel
       print *,(a(i,j), j=1, i-1),1, (0, j=i+1, dim) 
 
    end do !essayer en + compacte sans do par intervalle
  end subroutine   afficheL
 
 
 
  subroutine  afficheU(a)
    real, intent(inout), dimension(:,:) :: a
    integer ::dim,i,j
    dim=size(a,1)
    !mat carrée
    !cet ordre car affichage par lignes
 
    ! print *,((0,j=1,i-1) ,1,(a(i,j), j=i+1,dim), i=1, dim)  !!!optimisé
 
    do i=1,dim 
       print *, (0,j=1,i-1) ,1,(a(i,j), j=i+1,dim)
    end do
  end subroutine  afficheU
 
 
end module aln
 
 
 
 
lu.f90:
program lu
  !sans pivotage
  ! initialiser  le u pr somm part
 
 use aln
  implicit none
  integer, parameter :: dim = 4
  real r
  ! real, dimension(dim) :: u,v,rv
 
  integer :: i,j
 
  real, dimension(dim,dim) :: a,sov,luMat,l_u,l,u,M,N
  real, dimension(dim) :: b !
  call initialisation
 
  call aelu( a )
  !afficheL(a),afficheU(a)
 
 
  sov=a
  call   getL(a)
  l=a
  a=sov!car ça a modifié a
  call  getU(a)
  u=a
  a=sov
  print *, 'L= '
  call  afficheL(a)
  print * , 'U='
  call afficheU(a)
  print * , 'A-LU='
 
  M=a
  N=l*u
 
  call  afficheDiffM(M,N)
 
 
  ! print *,'u=\n',u(size(u):1:-1)
 
 
  call  luxeb(a,b)
 
contains 
  subroutine initialisation
 
    !  a = reshape( (/(((1.0+i)/j,i=1,dim),j=1,dim)/), (/dim,dim/))
    a = reshape( (/ 1.,  1., 1., 1., & 
         & 1., 0., 1., 0., &
         & 0., 1., 0., 1., &
         & 1. ,0., 0., 1. /), (/dim,dim/))
    b= reshape((/1 , 2,3,4 /), (/dim/))
 
  end subroutine initialisation
 
end program lu
et Makefile:
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
F90 = gfortran
lu:	lu.o aln.o
	$(F90) -o $@ $+
 
t1 : 	t1.o aln.o
	$(F90) -o $@ $+
 
lu.o : 	lu.f90 aln.mod
	$(F90) -c $<
 
t1.o : 	t1.f90 aln.mod
	$(F90) -c $<
 
 
aln.o aln.mod : aln.f90
	$(F90) -c $< 
 
 
# 
 
clean :
	rm *.o *.mod *~
En faisant make lu ça me met :
make -k lu
gfortran -c aln.f90
In file aln.f90:115

s=somm(lu(descente,:),y(:),1,descente-1)
1
Error: Procedure argument at (1) is INTENT(IN) while interface specifies INTENT(INOUT)
make: *** [aln.mod] Erreur 1
gfortran -c aln.f90
In file aln.f90:115

s=somm(lu(descente,:),y(:),1,descente-1)
1
Error: Procedure argument at (1) is INTENT(IN) while interface specifies INTENT(INOUT)
make: *** [aln.o] Erreur 1
make: La cible « lu » n'a pas pu être refabriquée à cause d'erreurs.
Pourquoi il n'est pas content avec mon somm ?