compute root-mean-square and max norms of a vector.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=ip), | intent(in) | :: | n | |||
real(kind=rp), | intent(in), | dimension(n) | :: | v | ||
real(kind=rp), | intent(inout) | :: | vrms | |||
real(kind=rp), | intent(inout) | :: | vmax |
subroutine rmsvec( n, v, vrms, vmax )
!! compute root-mean-square and max norms of a vector.
implicit none
integer(ip), intent(in) :: n
real(rp), dimension(n), intent(in) :: v
real(rp), intent(inout) :: vrms, vmax
integer(ip) :: i
! initialize
vrms = 0.0_rp
vmax = 0.0_rp
! loop over entries
do i = 1, n
! max norm
vmax = max(vmax,abs(v(i)))
! rms norm
vrms = vrms + v(i)*v(i)
enddo
vrms = sqrt(vrms/dble(n))
end subroutine rmsvec