Pour transposer une matrice en fortran 90 il existe la fonction TRANSPOSE, illustration:
\begin{equation}
A = \left( \begin{array}{ccc}
1 & 2 & 0 \\
4 & 3 & -1
\end{array}\right)
\end{equation}
\begin{equation}
A^t = \left( \begin{array}{ccc}
1 & 4 \\
2 & 3 \\
0 & -1
\end{array}\right)
\end{equation}
program transpose_array
implicit none
integer :: i,j
integer, dimension(2,3) :: MATRIX_A
integer, dimension(3,2) :: MATRIX_AT
!----------------------------------------------------------------------------------------!
! Matrix A
MATRIX_A(1,1) = 1
MATRIX_A(1,2) = 2
MATRIX_A(1,3) = 0
MATRIX_A(2,1) = 4
MATRIX_A(2,2) = 3
MATRIX_A(2,3) = -1
write(6,*) '---------- Matrix A ----------'
do i = 1, 2
write(6,*) MATRIX_A(i,1),MATRIX_A(i,2),MATRIX_A(i,3)
end do
!----------------------------------------------------------------------------------------!
MATRIX_AT = transpose(MATRIX_A)
write(6,*) '---------- Matrix transpose(A) ----------'
do i = 1, 3
write(6,*) MATRIX_AT(i,1),MATRIX_AT(i,2)
end do
!----------------------------------------------------------------------------------------!
end program transpose_array
donne
---------- Matrix A ----------
1 2 0
4 3 -1
---------- Matrix transpose(A) ----------
1 4
2 3
0 -1
Recherches associées
Liens | Site |
---|---|
TRANSPOSE — Transpose an array of rank two | gcc.gnu.org |
How can I efficiently transpose array and assign to an array with a different type | stackoverflow |
Intrinsic functions in Fortran 90 | www.nsc.liu.se |