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:
| Type | Intent | Optional | 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 |
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