Mohammad,
>Is there any code for calculating inverse matrix in general form (singular
>or non-singular) ?
There is no inverse for a singular matrix.
A very creative use of F90 syntax that I have seen was written (IIRC by Tim
Prince -- if not, I apologise to the author, anonymous in the code) for
David Frank's Test_FPU (sorry, I don't have the URL).
The fastest code that I have been able to put together uses LAPACK. If you
are on a machine which has access to an efficient library, e.g. CXML or
IMSL, the following code is pretty good.
SUBROUTINE LAPACK_INVERT(a,n)
INTEGER n
DOUBLE PRECISION a(n,n)
! Local Variables
INTEGER info,pivot(n)
DOUBLE PRECISION Work(n*64) ! Suggested optimal blocking size for DGETRI
CALL DGETRF(N,N,A,N,pivot,info)
CALL DGETRI(N,A,N,pivot,work,n*64,info)
END
For my problems, I've ignored tests on the info variable. Neither did Tim
in his routine do any equivalent tests for singularity.
On my VMS Alpha system using CXML, I tested a 1000 x 1000 run and for
default optimisation it took 39.59 CPU seconds for Tim's routine and 3.24
seconds for the CXML library. At the top optimisation level, Tim's routine
took 25.03 seconds -- obviously the library routine took about the same time
as before.
No other public domain code that I have seen comes anywhere close to either.
My copy of the old IBM Scientific Software Package routine MINV took about
250 CPU seconds.
The n*64 work array size, and as the argument, shaved quite a few seconds
off the run-time. This may not be optimal for my machine, but it is the
value used in the NETLIB LAPACK routine IALENV.
Regards, Paddy
Paddy O'Brien,
Transmission Development,
TransGrid,
PO Box A1000, Sydney South,
NSW 2000, Australia
(Street address, 201 Elizabeth Street)
Tel: +61 2 9284-3063
Fax: +61 2 9284-3050
Email: [log in to unmask]
Either "\'" or "\s" (to escape the apostrophe) seems to work for most
people,
but that little whizz-bang apostrophe gives me little spam.
|