function that calculates the trace of a square matrix
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=dp), | intent(in), | dimension(:, :) | :: | A |
function Trace(A) result(result) real(dp), dimension(:, :), intent(in) :: A real(dp) :: result integer :: i, N N = size(A, 1) if (size(A, 2) /= N) stop "Error: Matrix must be square." result = sum([(A(i, i), i=1, N)]) end function Trace