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:
9
complex(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
28
implicit none
29
! arguments
30
integer
,
intent(in)
:: n
31
complex(8), intent(inout) :: a(n,n)
32
! local variables
33
integer
i,m,info
34
! automatic arrays
35
integer
ipiv(n)
36
! perform an LU factorisation of the input matrix
37
call zgetrf(n,n,a,n,ipiv,info)
38
! multiply diagonal elements of U together
39
zmdet=a(1,1)
40
do
i=2,n
41
zmdet=zmdet*a(i,i)
42
end do
43
! determine the sign from the number of row interchanges
44
m=1
45
do
i=1,n
46
if
(ipiv(i) /= i) m=-m
47
end do
48
if
(m == -1) zmdet=-zmdet
49
end function
50
!EOC
51
zmdet.f90
Generated by
1.9.8