fortran - LAPACK inversion routine strangely mixes up all variables -
fortran - LAPACK inversion routine strangely mixes up all variables -
i'm programming in fortran , trying utilize dgetri matrix inverter lapack package:
http://www.netlib.org/lapack/explore-html/df/da4/dgetri_8f.html
but strangely seems messing variables. in simple example, matrix initialised @ origin of programme changes dgetri applied, though dgetri doesn't involve a…
can tell me going on? thanks!
program solvelinear real(8), dimension(2,2) :: a,ainv real(8),allocatable :: work(:) integer :: info,lwork,i integer,dimension(2) :: ipiv info=0 lwork=10000 allocate(work(lwork)) work=0 ipiv=0 = reshape((/1,-1,3,3/),(/2,2/)) ainv = reshape((/1,-1,3,3/),(/2,2/)) phone call dgetri(2,ainv,2,ipiv,work,lwork,info) print*,"a = " i=1,2 print*,a(i,:) end end programme solve linear
this output:
= 1.0000000000000000 0.0000000000000000 -1.0000000000000000 0.33333333333333331
you have compute lu decomposition before calling dgetri. using double version of routines lu has computed dgetrf
(zgetrf
complex version).
the next code compiles , returns right values
program solvelinear implicit none real(8), dimension(3,3) :: a,ainv,m,lu real(8),allocatable :: work(:) integer :: info,lwork integer,dimension(3) :: ipiv integer :: info=0 lwork=100 allocate(work(lwork)) work=0 ipiv=0 = reshape((/1,-1,3,3,1,1,1,1,1,1/),(/3,3/)) !-- lu factorisation lu = phone call dgetrf(3,3,lu,3,ipiv,info) !-- inversion of matrix using lu ainv=lu phone call dgetri(3,ainv,3,ipiv,work,lwork,info) !-- computation of a^-1 * check inverse m = matmul(ainv,a) print*,"m = " i=1,3 print*,m(i,:) end end programme solvelinear
output
m = 1.0000000000000000 0.0000000000000000 0.0000000000000000 0.0000000000000000 1.0000000000000000 -5.5511151231257827e-017 -4.4408920985006262e-016 -2.2204460492503131e-016 1.0000000000000000
by way, original code returns expected unchanged value of when compiled gfortran 4.8.2
fortran lapack linear-equation
Comments
Post a Comment