Compute the matrix trace (sum of the diagonal elements).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | n |
size of the matrix |
||
real(kind=wp), | intent(in), | dimension(n,n) | :: | mat |
the matrix |
the matrix trace
pure function matrix_trace(n,mat) result(trace) implicit none integer,intent(in) :: n !! size of the matrix real(wp),dimension(n,n),intent(in) :: mat !! the matrix real(wp) :: trace !! the matrix trace integer :: i !! counter trace = zero do i = 1, n trace = trace + mat(i,i) end do end function matrix_trace