Return in b the adjoint of the 3x3 matrix a, and its determinant. The inverse is defined as the adjoind divided by the determinant, so that inverse(a) = b/det
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=dp), | intent(in) | :: | a(3,3) | |||
real(kind=dp), | intent(out) | :: | b(3,3) | |||
real(kind=dp), | intent(out) | :: | det |
subroutine utility_inv3(a, b, det) !
!==================================================================!
! !
!! Return in b the adjoint of the 3x3 matrix a, and its
!! determinant.
!! The inverse is defined as the adjoind divided by the
!! determinant, so that inverse(a) = b/det
! !
!===================================================================
implicit none
real(kind=dp), intent(in) :: a(3, 3)
real(kind=dp), intent(out) :: b(3, 3)
real(kind=dp), intent(out) :: det
real(kind=dp):: work(6, 6)
integer :: i, j, k, l, ll, kk
do i = 1, 2
do j = 1, 2
do k = 1, 3
do l = 1, 3
kk = 3*(i - 1) + k
ll = 3*(j - 1) + l
work(kk, ll) = a(k, l)
end do
end do
end do
end do
det = 0.0_dp
do i = 1, 3
det = det + work(1, i)*work(2, i + 1)*work(3, i + 2)
end do
do i = 4, 6
det = det - work(1, i)*work(2, i - 1)*work(3, i - 2)
end do
do j = 1, 3
do i = 1, 3
b(j, i) = (work(i + 1, j + 1)*work(i + 2, j + 2) - work(i + 1, j + 2) &
*work(i + 2, j + 1))
end do
end do
return
end subroutine utility_inv3