eig_sym Subroutine

public subroutine eig_sym(matrix, e_values, e_vectors)

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in) :: matrix(:,:)
real(kind=dp), intent(out) :: e_values(size(matrix,1))
real(kind=dp), intent(out), optional :: e_vectors(size(matrix,1),size(matrix,2))

Contents

Source Code


Source Code

    subroutine eig_sym(matrix, e_values, e_vectors)
        real(dp), intent(in) :: matrix(:,:)
        real(dp), intent(out) :: e_values(size(matrix,1))
        real(dp), intent(out), optional :: e_vectors(size(matrix,1),size(matrix,2))
        character(*), parameter :: this_routine = 'eig_sym'
        integer :: n, info, lwork
        character(1) :: jobz
        real(dp) :: tmp_matrix(size(matrix,1),size(matrix,2))
        real(dp) :: work(3*size(matrix,1))

        n = size(matrix,1)
        lwork = 3*n

        tmp_matrix = matrix

        if (present(e_vectors)) then
            jobz = 'V'
        else
            jobz = 'N'
        end if

        call dsyev(&
            jobz, &
            'U', &
            n, &
            tmp_matrix, &
            n, &
            e_values, &
            work, &
            lwork, &
            info)
        if (info /= 0) call stop_all(this_routine, 'Failed in BLAS call.')

        if (present(e_vectors)) then
            e_vectors = tmp_matrix
        end if

    end subroutine eig_sym