The Elk Code
 
Loading...
Searching...
No Matches
zmdet.f90
Go to the documentation of this file.
1
2! Copyright (C) 2020 J. K. Dewhurst and S. Sharma.
3! This file is distributed under the terms of the GNU General Public License.
4! See the file COPYING for license details.
5
6!BOP
7! !ROUTINE: zmdet
8! !INTERFACE:
9complex(8) function zmdet(n,a)
10! !INPUT/OUTPUT PARAMETERS:
11! n : order of matrix (in,integer)
12! a : complex square matrix (inout,complex(n,n))
13! !DESCRIPTION:
14! Calculates the determinant of a complex matrix $A$ by using its $LU$
15! decomposition with partial pivoting. Let $A=PLU$ where $P$ is the
16! permutation matrix corresponding to row interchanges, then
17! \begin{align*}
18! |A|&=|P||L||U| \\
19! &=(-1)^p\prod_{i=1}^n U_{ii},
20! \end{align*}
21! where $p$ is the number of interchanges. Note that the input matrix is
22! destroyed on exit.
23!
24! !REVISION HISTORY:
25! Created January 2020 (JKD)
26!EOP
27!BOC
28implicit none
29! arguments
30integer, intent(in) :: n
31complex(8), intent(inout) :: a(n,n)
32! local variables
33integer i,m,info
34! automatic arrays
35integer ipiv(n)
36! perform an LU factorisation of the input matrix
37call zgetrf(n,n,a,n,ipiv,info)
38! multiply diagonal elements of U together
39zmdet=a(1,1)
40do i=2,n
41 zmdet=zmdet*a(i,i)
42end do
43! determine the sign from the number of row interchanges
44m=1
45do i=1,n
46 if (ipiv(i) /= i) m=-m
47end do
48if (m == -1) zmdet=-zmdet
49end function
50!EOC
51