Commit af246bca404c1a34ac64428f0f8cf29d21dd0228
1 parent
b85eed0171
Exists in
master
and in
3 other branches
+) Sorting of eigenvalues/eigenvectors is now optional
+) Documentation updated +) The test program test_matev has been updated to show the sort option git-svn-id: https://lxsd.femto-st.fr/svn/fvn@53 b657c933-2333-4658-acf2-d3c7c2708721
Showing 4 changed files with 1898 additions and 1912 deletions Side-by-side Diff
doc/fvn.pdf
No preview for this file type
doc/fvn.tex
| ... | ... | @@ -209,7 +209,7 @@ |
| 209 | 209 | \subsection{Eigenvalues/Eigenvectors} |
| 210 | 210 | \begin{verbatim} |
| 211 | 211 | Module : use fvn_linear |
| 212 | -call fvn_matev(d,a,evala,eveca,status) | |
| 212 | +call fvn_matev(d,a,evala,eveca,status,sortval) | |
| 213 | 213 | \end{verbatim} |
| 214 | 214 | \begin{itemize} |
| 215 | 215 | \item d (in) is an integer equal to the matrix rank |
| ... | ... | @@ -217,6 +217,7 @@ |
| 217 | 217 | \item evala (out) is a complex array of same kind as a. It contains the eigenvalues of matrix a |
| 218 | 218 | \item eveca (out) is a complex matrix of same kind as a. Its columns are the eigenvectors of matrix a : eveca(:,j)=jth eigenvector associated with eigenvalue evala(j). |
| 219 | 219 | \item status (out) is an optional integer equal to zero if something went wrong |
| 220 | + \item sortval (in) is an optional logical, if it is true the eigenvalues (and eigenvectors) are sorted in decreasing order of eigenvalues's modulus. | |
| 220 | 221 | \end{itemize} |
| 221 | 222 | |
| 222 | 223 |
fvn_linear/fvn_linear.f90
| ... | ... | @@ -1086,7 +1086,7 @@ |
| 1086 | 1086 | |
| 1087 | 1087 | end subroutine |
| 1088 | 1088 | |
| 1089 | -subroutine fvn_s_matev(d,a,evala,eveca,status) | |
| 1089 | +subroutine fvn_s_matev(d,a,evala,eveca,status,sortval) | |
| 1090 | 1090 | ! |
| 1091 | 1091 | ! integer d (in) : matrice rank |
| 1092 | 1092 | ! real a(d,d) (in) : The Matrix |
| ... | ... | @@ -1101,6 +1101,7 @@ |
| 1101 | 1101 | complex, intent(out) :: evala(d) |
| 1102 | 1102 | complex, intent(out) :: eveca(d,d) |
| 1103 | 1103 | integer, intent(out), optional :: status |
| 1104 | + logical, intent(in), optional :: sortval | |
| 1104 | 1105 | |
| 1105 | 1106 | real, allocatable :: wc_a(:,:) ! a working copy of a |
| 1106 | 1107 | integer :: info |
| 1107 | 1108 | |
| ... | ... | @@ -1160,11 +1161,13 @@ |
| 1160 | 1161 | deallocate(wc_a) |
| 1161 | 1162 | |
| 1162 | 1163 | ! sorting |
| 1163 | - call fvn_c_sort_eigen(d,evala,eveca) | |
| 1164 | + if (present(sortval) .and. sortval) then | |
| 1165 | + call fvn_c_sort_eigen(d,evala,eveca) | |
| 1166 | + end if | |
| 1164 | 1167 | |
| 1165 | 1168 | end subroutine |
| 1166 | 1169 | |
| 1167 | -subroutine fvn_d_matev(d,a,evala,eveca,status) | |
| 1170 | +subroutine fvn_d_matev(d,a,evala,eveca,status,sortval) | |
| 1168 | 1171 | ! |
| 1169 | 1172 | ! integer d (in) : matrice rank |
| 1170 | 1173 | ! double precision a(d,d) (in) : The Matrix |
| ... | ... | @@ -1179,6 +1182,7 @@ |
| 1179 | 1182 | double complex, intent(out) :: evala(d) |
| 1180 | 1183 | double complex, intent(out) :: eveca(d,d) |
| 1181 | 1184 | integer, intent(out), optional :: status |
| 1185 | + logical, intent(in), optional :: sortval | |
| 1182 | 1186 | |
| 1183 | 1187 | double precision, allocatable :: wc_a(:,:) ! a working copy of a |
| 1184 | 1188 | integer :: info |
| 1185 | 1189 | |
| ... | ... | @@ -1239,11 +1243,13 @@ |
| 1239 | 1243 | deallocate(wc_a) |
| 1240 | 1244 | |
| 1241 | 1245 | ! sorting |
| 1242 | - call fvn_z_sort_eigen(d,evala,eveca) | |
| 1246 | + if (present(sortval) .and. sortval) then | |
| 1247 | + call fvn_z_sort_eigen(d,evala,eveca) | |
| 1248 | + end if | |
| 1243 | 1249 | |
| 1244 | 1250 | end subroutine |
| 1245 | 1251 | |
| 1246 | -subroutine fvn_c_matev(d,a,evala,eveca,status) | |
| 1252 | +subroutine fvn_c_matev(d,a,evala,eveca,status,sortval) | |
| 1247 | 1253 | ! |
| 1248 | 1254 | ! integer d (in) : matrice rank |
| 1249 | 1255 | ! complex a(d,d) (in) : The Matrix |
| ... | ... | @@ -1258,6 +1264,7 @@ |
| 1258 | 1264 | complex, intent(out) :: evala(d) |
| 1259 | 1265 | complex, intent(out) :: eveca(d,d) |
| 1260 | 1266 | integer, intent(out), optional :: status |
| 1267 | + logical, intent(in), optional :: sortval | |
| 1261 | 1268 | |
| 1262 | 1269 | complex, allocatable :: wc_a(:,:) ! a working copy of a |
| 1263 | 1270 | integer :: info |
| 1264 | 1271 | |
| ... | ... | @@ -1290,11 +1297,13 @@ |
| 1290 | 1297 | deallocate(wc_a) |
| 1291 | 1298 | |
| 1292 | 1299 | ! sorting |
| 1293 | - call fvn_c_sort_eigen(d,evala,eveca) | |
| 1300 | + if (present(sortval) .and. sortval) then | |
| 1301 | + call fvn_c_sort_eigen(d,evala,eveca) | |
| 1302 | + end if | |
| 1294 | 1303 | |
| 1295 | 1304 | end subroutine |
| 1296 | 1305 | |
| 1297 | -subroutine fvn_z_matev(d,a,evala,eveca,status) | |
| 1306 | +subroutine fvn_z_matev(d,a,evala,eveca,status,sortval) | |
| 1298 | 1307 | ! |
| 1299 | 1308 | ! integer d (in) : matrice rank |
| 1300 | 1309 | ! double complex a(d,d) (in) : The Matrix |
| ... | ... | @@ -1309,6 +1318,7 @@ |
| 1309 | 1318 | double complex, intent(out) :: evala(d) |
| 1310 | 1319 | double complex, intent(out) :: eveca(d,d) |
| 1311 | 1320 | integer, intent(out), optional :: status |
| 1321 | + logical, intent(in), optional :: sortval | |
| 1312 | 1322 | |
| 1313 | 1323 | double complex, allocatable :: wc_a(:,:) ! a working copy of a |
| 1314 | 1324 | integer :: info |
| ... | ... | @@ -1340,8 +1350,9 @@ |
| 1340 | 1350 | deallocate(wc_a) |
| 1341 | 1351 | |
| 1342 | 1352 | ! sorting |
| 1343 | - call fvn_z_sort_eigen(d,evala,eveca) | |
| 1344 | - | |
| 1353 | + if (present(sortval) .and. sortval) then | |
| 1354 | + call fvn_z_sort_eigen(d,evala,eveca) | |
| 1355 | + end if | |
| 1345 | 1356 | end subroutine |
| 1346 | 1357 | |
| 1347 | 1358 |
fvn_test/test_matev.f90
| 1 | 1 | program test_matev |
| 2 | 2 | use fvn_linear |
| 3 | 3 | implicit none |
| 4 | -real(8),dimension(3,3) :: a | |
| 4 | +complex(8),dimension(3,3) :: a | |
| 5 | +real(8),dimension(3,3) :: ra,ia | |
| 5 | 6 | complex(8),dimension(3) :: evala |
| 6 | 7 | complex(8),dimension(3,3) :: eveca |
| 7 | 8 | integer :: status,i,j |
| 9 | + | |
| 8 | 10 | call init_random_seed() |
| 9 | -call random_number(a) | |
| 11 | +call random_number(ra) | |
| 12 | +call random_number(ia) | |
| 13 | +a=ra+fvn_i*ia | |
| 10 | 14 | a=a*100 |
| 11 | 15 | call fvn_matev(3,a,evala,eveca,status) |
| 12 | 16 | |
| 13 | 17 | write(*,*) "The matrix :" |
| 14 | -write (*,'(3(e12.5))') a | |
| 18 | +write (*,'(3("(",e12.5,",",e12.5,")"))') a | |
| 15 | 19 | write (*,*) |
| 16 | 20 | do i=1,3 |
| 17 | -write(*,'("Eigenvalue ",I3," : (",e12.5,",",e12.5,") ")') i,evala(i) | |
| 18 | -write(*,*) "Associated Eigenvector :" | |
| 19 | -do j=1,3 | |
| 20 | -write(*,'("(",e12.5,",",e12.5,") ")') eveca(j,i) | |
| 21 | + write(*,'("Eigenvalue ",I3," : (",e12.5,",",e12.5,") ")') i,evala(i) | |
| 22 | + write(*,'("Modulus : ",e12.5)') abs(evala(i)) | |
| 23 | + write(*,*) "Associated Eigenvector :" | |
| 24 | + do j=1,3 | |
| 25 | + write(*,'("(",e12.5,",",e12.5,") ")') eveca(j,i) | |
| 26 | + end do | |
| 27 | + write(*,*) | |
| 21 | 28 | end do |
| 22 | -write(*,*) | |
| 29 | + | |
| 30 | +! tri | |
| 31 | +write(*,*) "With sort option" | |
| 32 | +call fvn_matev(3,a,evala,eveca,status,.true.) | |
| 33 | +do i=1,3 | |
| 34 | + write(*,'("Eigenvalue ",I3," : (",e12.5,",",e12.5,") ")') i,evala(i) | |
| 35 | + write(*,'("Modulus : ",e12.5)') abs(evala(i)) | |
| 36 | + write(*,*) "Associated Eigenvector :" | |
| 37 | + do j=1,3 | |
| 38 | + write(*,'("(",e12.5,",",e12.5,") ")') eveca(j,i) | |
| 39 | + end do | |
| 40 | + write(*,*) | |
| 23 | 41 | end do |
| 42 | + | |
| 43 | + | |
| 24 | 44 | end program |