Télécharger invsvd.eso

Retour à la liste

Numérotation des lignes :

invsvd
  1. C INVSVD SOURCE CB215821 26/08/24 21:16:55 12622
  2. SUBROUTINE INVSVD(NM,M,N,A,W,MATU,U,MATV,V,iarr,RV1)
  3. c
  4. IMPLICIT INTEGER(I-N)
  5. integer i,j,k,l,m,n,ii,i1,kk,k1,ll,l1,mn,nm,its,iarr
  6. real*8 a(nm,n),w(n),u(nm,n),v(nm,n),rv1(n)
  7. real*8 c,f,g,h,s,x,y,z,scale,anorm
  8. real*8 sqrt,max,abs,sign
  9. logical matu,matv
  10. real*8 zero, one, two
  11. parameter(zero=0.0D0, one=1.0D0, two=2.0D0)
  12. c
  13. c Adaptation to Esope
  14. c A. BECCANTINI
  15. c DRN/DMT/SEMT/LTMF
  16. c 18.08.00
  17. c
  18. c this subroutine is a translation of the algol procedure svd,
  19. c num. math. 14, 403-420(1970) by golub and reinsch.
  20. c handbook for auto. comp., vol ii-linear algebra, 134-151(1971).
  21. c
  22. c this subroutine determines the singular value decomposition
  23. c t
  24. c a=usv of a real m by n rectangular matrix. householder
  25. c bidiagonalization and a variant of the qr algorithm are used.
  26. c
  27. c on input.
  28. c
  29. c nm must be set to the row dimension of two-dimensional
  30. c array parameters as declared in the calling program
  31. c dimension statement. note that nm must be at least
  32. c as large as the maximum of m and n.
  33. c
  34. c m is the number of rows of a (and u).
  35. c
  36. c n is the number of columns of a (and u) and the order of v.
  37. c
  38. c a contains the rectangular input matrix to be decomposed.
  39. c
  40. c matu should be set to .true. if the u matrix in the
  41. c decomposition is desired, and to .false. otherwise.
  42. c
  43. c matv should be set to .true. if the v matrix in the
  44. c decomposition is desired, and to .false. otherwise.
  45. c
  46. c on output.
  47. c
  48. c a is unaltered (unless overwritten by u or v).
  49. c
  50. c w contains the n (non-negative) singular values of a (the
  51. c diagonal elements of s). they are unordered. if an
  52. c error exit is made, the singular values should be correct
  53. c for indices iarr+1,iarr+2,...,n.
  54. c
  55. c u contains the matrix u (orthogonal column vectors) of the
  56. c decomposition if matu has been set to .true. otherwise
  57. c u is used as a temporary array. u may coincide with a.
  58. c if an error exit is made, the columns of u corresponding
  59. c to indices of correct singular values should be correct.
  60. c
  61. c v contains the matrix v (orthogonal) of the decomposition if
  62. c matv has been set to .true. otherwise v is not referenced.
  63. c v may also coincide with a if u is not needed. if an error
  64. c exit is made, the columns of v corresponding to indices of
  65. c correct singular values should be correct.
  66. c
  67. c iarr is set to
  68. c zero for normal return,
  69. c k if the k-th singular value has not been
  70. c determined after 30 iterations.
  71. c
  72. c rv1 is a temporary storage array.
  73. c
  74. c this is a modified version of a routine from the eispack
  75. c collection by the nats project
  76. c
  77. c modified to eliminate machep
  78. c
  79. iarr = 0
  80. c
  81. do 1002 i = 1, m
  82. c
  83. do 100 j = 1, n
  84. u(i,j) = a(i,j)
  85. 100 continue
  86. 1002 CONTINUE
  87. c .......... householder reduction to bidiagonal form ..........
  88. g = zero
  89. scale = zero
  90. anorm = zero
  91. c
  92. do 300 i = 1, n
  93. l = i + 1
  94. rv1(i) = scale * g
  95. g = zero
  96. s = zero
  97. scale = zero
  98. if (i .gt. m) go to 210
  99. c
  100. do 120 k = i, m
  101. scale = scale + abs(u(k,i))
  102. 120 CONTINUE
  103. c
  104. if (scale .eq. zero) go to 210
  105. c
  106. do 130 k = i, m
  107. u(k,i) = u(k,i) / scale
  108. s = s + u(k,i)**2
  109. 130 continue
  110. c
  111. f = u(i,i)
  112. g = -sign(sqrt(s),f)
  113. h = f * g - s
  114. u(i,i) = f - g
  115. if (i .eq. n) go to 190
  116. c
  117. do 1003 j = l, n
  118. s = zero
  119. c
  120. do 140 k = i, m
  121. s = s + u(k,i) * u(k,j)
  122. 140 CONTINUE
  123. c
  124. f = s / h
  125. c
  126. do 150 k = i, m
  127. u(k,j) = u(k,j) + f * u(k,i)
  128. 150 continue
  129. 1003 CONTINUE
  130. c
  131. 190 do 200 k = i, m
  132. 200 u(k,i) = scale * u(k,i)
  133. c
  134. 210 w(i) = scale * g
  135. g = zero
  136. s = zero
  137. scale = zero
  138. if (i .gt. m .or. i .eq. n) go to 290
  139. c
  140. do 220 k = l, n
  141. scale = scale + abs(u(i,k))
  142. 220 CONTINUE
  143. c
  144. if (scale .eq. zero) go to 290
  145. c
  146. do 230 k = l, n
  147. u(i,k) = u(i,k) / scale
  148. s = s + u(i,k)**2
  149. 230 continue
  150. c
  151. f = u(i,l)
  152. g = -sign(sqrt(s),f)
  153. h = f * g - s
  154. u(i,l) = f - g
  155. c
  156. do 240 k = l, n
  157. rv1(k) = u(i,k) / h
  158. 240 CONTINUE
  159. c
  160. if (i .eq. m) go to 270
  161. c
  162. do 1004 j = l, m
  163. s = zero
  164. c
  165. do 250 k = l, n
  166. s = s + u(j,k) * u(i,k)
  167. 250 CONTINUE
  168. c
  169. do 260 k = l, n
  170. u(j,k) = u(j,k) + s * rv1(k)
  171. 260 continue
  172. 1004 CONTINUE
  173. c
  174. 270 do 280 k = l, n
  175. 280 u(i,k) = scale * u(i,k)
  176. c
  177. 290 anorm = max(anorm,abs(w(i))+abs(rv1(i)))
  178. 300 continue
  179. c .......... accumulation of right-hand transformations ..........
  180. if (.not. matv) go to 410
  181. c .......... for i=n step -1 until 1 do -- ..........
  182. do 400 ii = 1, n
  183. i = n + 1 - ii
  184. if (i .eq. n) go to 390
  185. if (g .eq. zero) go to 360
  186. c
  187. do 320 j = l, n
  188. c .......... double division avoids possible underflow ..........
  189. v(j,i) = (u(i,j) / u(i,l)) / g
  190. 320 CONTINUE
  191. c
  192. do 1005 j = l, n
  193. s = zero
  194. c
  195. do 340 k = l, n
  196. s = s + u(i,k) * v(k,j)
  197. 340 CONTINUE
  198. c
  199. do 350 k = l, n
  200. v(k,j) = v(k,j) + s * v(k,i)
  201. 350 continue
  202. 1005 CONTINUE
  203. c
  204. 360 do 380 j = l, n
  205. v(i,j) = zero
  206. v(j,i) = zero
  207. 380 continue
  208. c
  209. 390 v(i,i) = one
  210. g = rv1(i)
  211. l = i
  212. 400 continue
  213. c .......... accumulation of left-hand transformations ..........
  214. 410 if (.not. matu) go to 510
  215. c ..........for i=min(m,n) step -1 until 1 do -- ..........
  216. mn = n
  217. if (m .lt. n) mn = m
  218. c
  219. do 500 ii = 1, mn
  220. i = mn + 1 - ii
  221. l = i + 1
  222. g = w(i)
  223. if (i .eq. n) go to 430
  224. c
  225. do 420 j = l, n
  226. u(i,j) = zero
  227. 420 CONTINUE
  228. c
  229. 430 if (g .eq. zero) go to 475
  230. if (i .eq. mn) go to 460
  231. c
  232. do 1006 j = l, n
  233. s = zero
  234. c
  235. do 440 k = l, m
  236. s = s + u(k,i) * u(k,j)
  237. 440 CONTINUE
  238. c .......... double division avoids possible underflow ..........
  239. f = (s / u(i,i)) / g
  240. c
  241. do 450 k = i, m
  242. u(k,j) = u(k,j) + f * u(k,i)
  243. 450 continue
  244. 1006 CONTINUE
  245. c
  246. 460 do 470 j = i, m
  247. 470 u(j,i) = u(j,i) / g
  248. c
  249. go to 490
  250. c
  251. 475 do 480 j = i, m
  252. 480 u(j,i) = zero
  253. c
  254. 490 u(i,i) = u(i,i) + one
  255. 500 continue
  256. c .......... diagonalization of the bidiagonal form ..........
  257. c .......... for k=n step -1 until 1 do -- ..........
  258. 510 do 700 kk = 1, n
  259. k1 = n - kk
  260. k = k1 + 1
  261. its = 0
  262. c .......... test for splitting.
  263. c for l=k step -1 until 1 do -- ..........
  264. 520 do 530 ll = 1, k
  265. l1 = k - ll
  266. l = l1 + 1
  267. if (abs(rv1(l)) + anorm .eq. anorm) go to 565
  268. c .......... rv1(1) is always zero, so there is no exit
  269. c through the bottom of the loop ..........
  270. if (abs(w(l1)) + anorm .eq. anorm) go to 540
  271. 530 continue
  272. c .......... cancellation of rv1(l) if l greater than 1 ..........
  273. 540 c = zero
  274. s = one
  275. c
  276. do 560 i = l, k
  277. f = s * rv1(i)
  278. rv1(i) = c * rv1(i)
  279. if (abs(f) + anorm .eq. anorm) go to 565
  280. g = w(i)
  281. h = sqrt(f*f+g*g)
  282. w(i) = h
  283. c = g / h
  284. s = -f / h
  285. if (.not. matu) go to 560
  286. c
  287. do 550 j = 1, m
  288. y = u(j,l1)
  289. z = u(j,i)
  290. u(j,l1) = y * c + z * s
  291. u(j,i) = -y * s + z * c
  292. 550 continue
  293. c
  294. 560 continue
  295. c .......... test for convergence ..........
  296. 565 z = w(k)
  297. if (l .eq. k) go to 650
  298. c .......... shift from bottom 2 by 2 minor ..........
  299. if (its .eq. 30) go to 1000
  300. its = its + 1
  301. x = w(l)
  302. y = w(k1)
  303. g = rv1(k1)
  304. h = rv1(k)
  305. f = ((y - z) * (y + z) + (g - h) * (g + h)) / (two * h * y)
  306. g = sqrt(f*f+one)
  307. f = ((x - z) * (x + z) + h * (y / (f + sign(g,f)) - h)) / x
  308. c .......... next qr transformation ..........
  309. c = one
  310. s = one
  311. c
  312. do 600 i1 = l, k1
  313. i = i1 + 1
  314. g = rv1(i)
  315. y = w(i)
  316. h = s * g
  317. g = c * g
  318. z = sqrt(f*f+h*h)
  319. rv1(i1) = z
  320. c = f / z
  321. s = h / z
  322. f = x * c + g * s
  323. g = -x * s + g * c
  324. h = y * s
  325. y = y * c
  326. if (.not. matv) go to 575
  327. c
  328. do 570 j = 1, n
  329. x = v(j,i1)
  330. z = v(j,i)
  331. v(j,i1) = x * c + z * s
  332. v(j,i) = -x * s + z * c
  333. 570 continue
  334. c
  335. 575 z = sqrt(f*f+h*h)
  336. w(i1) = z
  337. c .......... rotation can be arbitrary if z is zero ..........
  338. if (z .eq. zero) go to 580
  339. c = f / z
  340. s = h / z
  341. 580 f = c * g + s * y
  342. x = -s * g + c * y
  343. if (.not. matu) go to 600
  344. c
  345. do 590 j = 1, m
  346. y = u(j,i1)
  347. z = u(j,i)
  348. u(j,i1) = y * c + z * s
  349. u(j,i) = -y * s + z * c
  350. 590 continue
  351. c
  352. 600 continue
  353. c
  354. rv1(l) = zero
  355. rv1(k) = f
  356. w(k) = x
  357. go to 520
  358. c .......... convergence ..........
  359. 650 if (z .ge. zero) go to 700
  360. c .......... w(k) is made non-negative ..........
  361. w(k) = -z
  362. if (.not. matv) go to 700
  363. c
  364. do 690 j = 1, n
  365. v(j,k) = -v(j,k)
  366. 690 CONTINUE
  367. c
  368. 700 continue
  369. c
  370. go to 1001
  371. c .......... set error -- no convergence to a
  372. c singular value after 30 iterations ..........
  373. 1000 iarr = k
  374. 1001 return
  375. end
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  

© Cast3M 2003 - Tous droits réservés.
Mentions légales