Performs a direct calculation of the inverse of a 3×3 matrix.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in) | :: | a(3,3) |
Matrix |
Inverse matrix
pure function matinv_3x3(a) result(b) !> Matrix real(wp), intent(in) :: a(3, 3) !> Inverse matrix real(wp) :: b(3, 3) real(wp) :: detinv ! Calculate the inverse determinant of the matrix detinv = 1.0_wp/matdet_3x3(a) ! Calculate the inverse of the matrix b(1, 1) = +detinv * (a(2, 2) * a(3, 3) - a(2, 3) * a(3, 2)) b(2, 1) = -detinv * (a(2, 1) * a(3, 3) - a(2, 3) * a(3, 1)) b(3, 1) = +detinv * (a(2, 1) * a(3, 2) - a(2, 2) * a(3, 1)) b(1, 2) = -detinv * (a(1, 2) * a(3, 3) - a(1, 3) * a(3, 2)) b(2, 2) = +detinv * (a(1, 1) * a(3, 3) - a(1, 3) * a(3, 1)) b(3, 2) = -detinv * (a(1, 1) * a(3, 2) - a(1, 2) * a(3, 1)) b(1, 3) = +detinv * (a(1, 2) * a(2, 3) - a(1, 3) * a(2, 2)) b(2, 3) = -detinv * (a(1, 1) * a(2, 3) - a(1, 3) * a(2, 1)) b(3, 3) = +detinv * (a(1, 1) * a(2, 2) - a(1, 2) * a(2, 1)) end function matinv_3x3