norm_cmplx Function

public function norm_cmplx(vec, p_in)

Arguments

Type IntentOptional Attributes Name
complex(kind=dp), intent(in) :: vec(:)
integer, intent(in), optional :: p_in

Return Value real(kind=dp)


Contents

Source Code


Source Code

    real(dp) function norm_cmplx(vec,p_in)
        ! function to calculate the Lp norm of a given vector
        ! if p_in = -1 this indicates the p_inf norm
        complex(dp), intent(in) :: vec(:)
        integer, intent(in), optional :: p_in
        integer :: p, i

        if (present(p_in)) then
            p = p_in
        else
            ! default is the L2 norm
            p = 2
        end if

        if (p == -1) then
            norm_cmplx = maxval(abs(vec))
        else
            norm_cmplx = 0.0_dp
            do i = 1, size(vec)
                norm_cmplx = norm_cmplx + abs(vec(i))**p
            end do

            norm_cmplx = norm_cmplx**(1.0_dp/real(p,dp))
        end if

    end function norm_cmplx