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
| program essai
implicit none
real, dimension(1:3,1:3) :: A
real, dimension(1:3,1:3) :: B
real, dimension(:,:), allocatable :: C
integer :: i,j
A(1,1) = 1.0
A(1,2) = 2.0
A(1,3) = 3.0
A(2,1) = 4.0
A(2,2) = 1.0
A(2,3) = 2.0
A(3,1) = 3.0
A(3,2) = 4.0
A(3,3) = 5.0
B(1,1) = 1.0
B(1,2) = 2.0
B(1,3) = 3.0
B(2,1) = 4.0
B(2,2) = 1.0
B(2,3) = 2.0
B(3,1) = 3.0
B(3,2) = 4.0
B(3,3) = 5.0
call Produit_M(A,B,3,3,3,3,C)
do i=1, 3
do j=1, 3
print*,C(i,j)
end do
print*,''
end do
deallocate(C)
contains
!!!CREER UNE MATRICE EN ALLOCATION DYNAMIQUE!!!
!!!EN ARGUMENT : NOM DE LA MATRICE, ET DIMENSIONS!!!
subroutine Creer_matrice(A,nA,mA)
real, dimension(:,:),allocatable, intent(out) :: A
integer, intent(in) :: nA, mA
allocate(A(1:nA,1:mA))
end subroutine Creer_matrice
!!! SUBROUTINE DE PRODUIT DE DEUX MATRICES !!!
!!!EN ARGUMENTS : MATRICE A, MATRICE B, DIM DE A DIM DE B, MATRICE RES RESULTAT !!!
subroutine Produit_M(A,B,nA,mA,nB,mB,Res)
implicit none
real, dimension(1:nA,1:mA), intent(in) :: A
real, dimension(1:nB,1:mB), intent(in) :: B
real, dimension(:,:), allocatable, intent(out) :: Res
integer, intent(in) :: nA,mA,nB,mB
integer :: i,j,k
test_comp: if (mA == nB) then
call Creer_matrice(Res,nA,mB)
do j=1, mB
do i=1, nA
do k=1,mA
Res(i,j) = Res(i,j) + A(i,k)*B(k,j)
end do
end do
end do
else
print*,'MATRICES INCOMPATIBLES !'
end if test_comp
end subroutine Produit_M
end program essai |
Partager