Eigen Subroutine

public subroutine Eigen(A, lambda, vp, method, k)

Computes the eigenvalues and eigenvectors of a matrix A with A a square matrix, λ the eigenvalue, and v the eigenvector. This subroutine allows you to choose the method for computing eigenvalues and eigenvectors:

  • Power iteration
  • QR algorithm (with or without shift) The default method is Power iteration.

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in), dimension(:, :) :: A
real(kind=dp), intent(out), dimension(:) :: lambda
real(kind=dp), intent(out), optional, dimension(:, :) :: vp
character(len=*), intent(in), optional :: method
integer, intent(in), optional :: k

Calls

proc~~eigen~~CallsGraph proc~eigen Eigen proc~identity_n Identity_n proc~eigen->proc~identity_n proc~normalise normalise proc~eigen->proc~normalise proc~qr_decomposition QR_decomposition proc~eigen->proc~qr_decomposition proc~norm_2_real norm_2_real proc~normalise->proc~norm_2_real proc~qr_givens_decomposition QR_Givens_decomposition proc~qr_decomposition->proc~qr_givens_decomposition proc~qr_gram_schmidt_classical_decomposition QR_Gram_Schmidt_Classical_decomposition proc~qr_decomposition->proc~qr_gram_schmidt_classical_decomposition proc~qr_gram_schmidt_modified_decomposition QR_Gram_Schmidt_Modified_decomposition proc~qr_decomposition->proc~qr_gram_schmidt_modified_decomposition proc~qr_householder_decomposition QR_Householder_decomposition proc~qr_decomposition->proc~qr_householder_decomposition proc~qr_givens_decomposition->proc~identity_n proc~rotation_matrix rotation_matrix proc~qr_givens_decomposition->proc~rotation_matrix proc~qr_householder_decomposition->proc~identity_n proc~rotation_matrix->proc~identity_n

Called by

proc~~eigen~~CalledByGraph proc~eigen Eigen proc~is_spd is_SPD proc~is_spd->proc~eigen

Source Code

    subroutine Eigen(A, lambda, vp, method, k)
        real(dp), dimension(:, :), intent(in) :: A
        character(LEN=*), optional, intent(in) :: method
        integer, optional, intent(in) :: k
        real(dp), dimension(:, :), optional, intent(out) :: vp
        real(dp), dimension(:), intent(out) :: lambda
        real(dp), dimension(size(A, 1), size(A, 1)) :: A_tmp
        real(dp), dimension(size(A, 1), size(A, 1)) :: vp_tmp
        character(LEN=50) :: base_method
        integer :: N, i, k_max, pos

        if (present(k)) then
            if (k <= 0) stop "ERROR :: k must be a positive integer"
            k_max = k
        else
            k_max = MAX_ITERATION
        end if

        N = size(A, 1)
        if (size(A, 2) /= N) stop "ERROR :: Matrix A not square"

        if (size(lambda, 1) /= N) stop "ERROR :: dimension lambda"
        if (present(vp) .and. (size(vp, 1) /= N .or. size(vp, 2) /= N)) stop "ERROR :: dimension vp"

        if (method == "Power_iteration") then

            A_tmp = A
            do i = 1, N
                call Power_iteration(A_tmp, lambda(i), vp_tmp(i, :), k_max)
                A_tmp = deflation(A_tmp, lambda(i), vp_tmp(i, :), k_max)
            end do

            if (present(vp)) vp = vp_tmp

        else if (index(method, "QR") == 1) then

            if (present(vp)) vp = 0
            if (present(vp)) print*,"WARNING :: No solution for eigenvectors with the QR method"

            pos = index(trim(method), "_Shifted")

            if (pos > 0 .and. pos + 7 == len_trim(method)) then
                base_method = method(:pos - 1)
                call Eigen_QR_Shifted(A, lambda, base_method, N, k_max)
            else
                call Eigen_QR(A, lambda, method, N, k_max)
            end if

        else
            stop "ERROR :: Wrong method for Eigen"
        end if

    end subroutine Eigen