Chapitre 6. Programmation en R
273
23
! d’une matrice g´ en´ erale A de dimension M x N
24
! en utilisant un pivot partiel avec des ´ echanges de lignes.
25
call DGETRF (n , n , Ainv , n , ipiv , info )
26
27
if ( info /= 0) then
28
stop 'La matrice est num´ eriquement singuli` ere!'
29
end if
30
31
! DGETRI calcule l’inverse d’une matrice en utilisant
32
! la factorisation LU calcul´ ee par DGETRF.
33
call DGETRI (n , Ainv , n , ipiv , work , n , info )
34
35
if ( info /= 0) then
36
stop 'Inversion de la matrice: ´ echec!'
37
end if
38 end subroutine invF
Pour compiler ce code, lancez les instructions suivantes dans une fenˆ etre de
commandes MS-DOS :
cd %HOMEPATH%/Desktop # ` A adapter ` a votre cas.
gfortran -c inv.f90 -o invBis.o -I"C:/lapack"
gfortran -shared -o invBis.dll invBis.o -I"C:/lapack" ^
C:/lapack/liblapack.a C:/lapack/librefblas.a
Linux
Sous Linux, on utilisera les instructions suivantes :
gfortran -c inv.f90 -o invBis.o -fPIC
gfortran -shared -o invBis.so invBis.o /usr/lib64/liblapack.so.3
Apr` es avoir cr´ e´ e le fichier invBis.dll (ou invBis.so sous Linux) au moyen
des instructions pr´ ec´ edentes, vous pouvez lancer R et y taper les instructions
suivantes :
> dyn.load(paste("invBis",.Platform$dynlib.ext,sep=""))
> A <- matrix(rnorm(4),nrow=2)
> B <- matrix(0,nrow=2,ncol=2)
> .Fortran("invF",A,res=B,2L)$res
[,1]
[,2]
[1,] -0.1145578 1.770077
[2,] 0.8990205 2.157801
> solve(A)
[,1]
[,2]
[1,] -0.1145578 1.770077
[2,] 0.8990205 2.157801
273
23
! d’une matrice g´ en´ erale A de dimension M x N
24
! en utilisant un pivot partiel avec des ´ echanges de lignes.
25
call DGETRF (n , n , Ainv , n , ipiv , info )
26
27
if ( info /= 0) then
28
stop 'La matrice est num´ eriquement singuli` ere!'
29
end if
30
31
! DGETRI calcule l’inverse d’une matrice en utilisant
32
! la factorisation LU calcul´ ee par DGETRF.
33
call DGETRI (n , Ainv , n , ipiv , work , n , info )
34
35
if ( info /= 0) then
36
stop 'Inversion de la matrice: ´ echec!'
37
end if
38 end subroutine invF
Pour compiler ce code, lancez les instructions suivantes dans une fenˆ etre de
commandes MS-DOS :
cd %HOMEPATH%/Desktop # ` A adapter ` a votre cas.
gfortran -c inv.f90 -o invBis.o -I"C:/lapack"
gfortran -shared -o invBis.dll invBis.o -I"C:/lapack" ^
C:/lapack/liblapack.a C:/lapack/librefblas.a
Linux
Sous Linux, on utilisera les instructions suivantes :
gfortran -c inv.f90 -o invBis.o -fPIC
gfortran -shared -o invBis.so invBis.o /usr/lib64/liblapack.so.3
Apr` es avoir cr´ e´ e le fichier invBis.dll (ou invBis.so sous Linux) au moyen
des instructions pr´ ec´ edentes, vous pouvez lancer R et y taper les instructions
suivantes :
> dyn.load(paste("invBis",.Platform$dynlib.ext,sep=""))
> A <- matrix(rnorm(4),nrow=2)
> B <- matrix(0,nrow=2,ncol=2)
> .Fortran("invF",A,res=B,2L)$res
[,1]
[,2]
[1,] -0.1145578 1.770077
[2,] 0.8990205 2.157801
> solve(A)
[,1]
[,2]
[1,] -0.1145578 1.770077
[2,] 0.8990205 2.157801
