Télécharger invsvd.eso

Retour à la liste

Numérotation des lignes :

invsvd
  1. C INVSVD SOURCE CB215821 26/10/26 21:15:41 12682
  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. u(k,i) = scale * u(k,i)
  133. 200 CONTINUE
  134. c
  135. 210 w(i) = scale * g
  136. g = zero
  137. s = zero
  138. scale = zero
  139. if (i .gt. m .or. i .eq. n) go to 290
  140. c
  141. do 220 k = l, n
  142. scale = scale + abs(u(i,k))
  143. 220 CONTINUE
  144. c
  145. if (scale .eq. zero) go to 290
  146. c
  147. do 230 k = l, n
  148. u(i,k) = u(i,k) / scale
  149. s = s + u(i,k)**2
  150. 230 continue
  151. c
  152. f = u(i,l)
  153. g = -sign(sqrt(s),f)
  154. h = f * g - s
  155. u(i,l) = f - g
  156. c
  157. do 240 k = l, n
  158. rv1(k) = u(i,k) / h
  159. 240 CONTINUE
  160. c
  161. if (i .eq. m) go to 270
  162. c
  163. do 1004 j = l, m
  164. s = zero
  165. c
  166. do 250 k = l, n
  167. s = s + u(j,k) * u(i,k)
  168. 250 CONTINUE
  169. c
  170. do 260 k = l, n
  171. u(j,k) = u(j,k) + s * rv1(k)
  172. 260 continue
  173. 1004 CONTINUE
  174. c
  175. 270 do 280 k = l, n
  176. u(i,k) = scale * u(i,k)
  177. 280 CONTINUE
  178. c
  179. 290 anorm = max(anorm,abs(w(i))+abs(rv1(i)))
  180. 300 continue
  181. c .......... accumulation of right-hand transformations ..........
  182. if (.not. matv) go to 410
  183. c .......... for i=n step -1 until 1 do -- ..........
  184. do 400 ii = 1, n
  185. i = n + 1 - ii
  186. if (i .eq. n) go to 390
  187. if (g .eq. zero) go to 360
  188. c
  189. do 320 j = l, n
  190. c .......... double division avoids possible underflow ..........
  191. v(j,i) = (u(i,j) / u(i,l)) / g
  192. 320 CONTINUE
  193. c
  194. do 1005 j = l, n
  195. s = zero
  196. c
  197. do 340 k = l, n
  198. s = s + u(i,k) * v(k,j)
  199. 340 CONTINUE
  200. c
  201. do 350 k = l, n
  202. v(k,j) = v(k,j) + s * v(k,i)
  203. 350 continue
  204. 1005 CONTINUE
  205. c
  206. 360 do 380 j = l, n
  207. v(i,j) = zero
  208. v(j,i) = zero
  209. 380 continue
  210. c
  211. 390 v(i,i) = one
  212. g = rv1(i)
  213. l = i
  214. 400 continue
  215. c .......... accumulation of left-hand transformations ..........
  216. 410 if (.not. matu) go to 510
  217. c ..........for i=min(m,n) step -1 until 1 do -- ..........
  218. mn = n
  219. if (m .lt. n) mn = m
  220. c
  221. do 500 ii = 1, mn
  222. i = mn + 1 - ii
  223. l = i + 1
  224. g = w(i)
  225. if (i .eq. n) go to 430
  226. c
  227. do 420 j = l, n
  228. u(i,j) = zero
  229. 420 CONTINUE
  230. c
  231. 430 if (g .eq. zero) go to 475
  232. if (i .eq. mn) go to 460
  233. c
  234. do 1006 j = l, n
  235. s = zero
  236. c
  237. do 440 k = l, m
  238. s = s + u(k,i) * u(k,j)
  239. 440 CONTINUE
  240. c .......... double division avoids possible underflow ..........
  241. f = (s / u(i,i)) / g
  242. c
  243. do 450 k = i, m
  244. u(k,j) = u(k,j) + f * u(k,i)
  245. 450 continue
  246. 1006 CONTINUE
  247. c
  248. 460 do 470 j = i, m
  249. u(j,i) = u(j,i) / g
  250. 470 CONTINUE
  251. c
  252. go to 490
  253. c
  254. 475 do 480 j = i, m
  255. u(j,i) = zero
  256. 480 CONTINUE
  257. c
  258. 490 u(i,i) = u(i,i) + one
  259. 500 continue
  260. c .......... diagonalization of the bidiagonal form ..........
  261. c .......... for k=n step -1 until 1 do -- ..........
  262. 510 do 700 kk = 1, n
  263. k1 = n - kk
  264. k = k1 + 1
  265. its = 0
  266. c .......... test for splitting.
  267. c for l=k step -1 until 1 do -- ..........
  268. 520 do 530 ll = 1, k
  269. l1 = k - ll
  270. l = l1 + 1
  271. if (abs(rv1(l)) + anorm .eq. anorm) go to 565
  272. c .......... rv1(1) is always zero, so there is no exit
  273. c through the bottom of the loop ..........
  274. if (abs(w(l1)) + anorm .eq. anorm) go to 540
  275. 530 continue
  276. c .......... cancellation of rv1(l) if l greater than 1 ..........
  277. 540 c = zero
  278. s = one
  279. c
  280. do 560 i = l, k
  281. f = s * rv1(i)
  282. rv1(i) = c * rv1(i)
  283. if (abs(f) + anorm .eq. anorm) go to 565
  284. g = w(i)
  285. h = sqrt(f*f+g*g)
  286. w(i) = h
  287. c = g / h
  288. s = -f / h
  289. if (.not. matu) go to 560
  290. c
  291. do 550 j = 1, m
  292. y = u(j,l1)
  293. z = u(j,i)
  294. u(j,l1) = y * c + z * s
  295. u(j,i) = -y * s + z * c
  296. 550 continue
  297. c
  298. 560 continue
  299. c .......... test for convergence ..........
  300. 565 z = w(k)
  301. if (l .eq. k) go to 650
  302. c .......... shift from bottom 2 by 2 minor ..........
  303. if (its .eq. 30) go to 1000
  304. its = its + 1
  305. x = w(l)
  306. y = w(k1)
  307. g = rv1(k1)
  308. h = rv1(k)
  309. f = ((y - z) * (y + z) + (g - h) * (g + h)) / (two * h * y)
  310. g = sqrt(f*f+one)
  311. f = ((x - z) * (x + z) + h * (y / (f + sign(g,f)) - h)) / x
  312. c .......... next qr transformation ..........
  313. c = one
  314. s = one
  315. c
  316. do 600 i1 = l, k1
  317. i = i1 + 1
  318. g = rv1(i)
  319. y = w(i)
  320. h = s * g
  321. g = c * g
  322. z = sqrt(f*f+h*h)
  323. rv1(i1) = z
  324. c = f / z
  325. s = h / z
  326. f = x * c + g * s
  327. g = -x * s + g * c
  328. h = y * s
  329. y = y * c
  330. if (.not. matv) go to 575
  331. c
  332. do 570 j = 1, n
  333. x = v(j,i1)
  334. z = v(j,i)
  335. v(j,i1) = x * c + z * s
  336. v(j,i) = -x * s + z * c
  337. 570 continue
  338. c
  339. 575 z = sqrt(f*f+h*h)
  340. w(i1) = z
  341. c .......... rotation can be arbitrary if z is zero ..........
  342. if (z .eq. zero) go to 580
  343. c = f / z
  344. s = h / z
  345. 580 f = c * g + s * y
  346. x = -s * g + c * y
  347. if (.not. matu) go to 600
  348. c
  349. do 590 j = 1, m
  350. y = u(j,i1)
  351. z = u(j,i)
  352. u(j,i1) = y * c + z * s
  353. u(j,i) = -y * s + z * c
  354. 590 continue
  355. c
  356. 600 continue
  357. c
  358. rv1(l) = zero
  359. rv1(k) = f
  360. w(k) = x
  361. go to 520
  362. c .......... convergence ..........
  363. 650 if (z .ge. zero) go to 700
  364. c .......... w(k) is made non-negative ..........
  365. w(k) = -z
  366. if (.not. matv) go to 700
  367. c
  368. do 690 j = 1, n
  369. v(j,k) = -v(j,k)
  370. 690 CONTINUE
  371. c
  372. 700 continue
  373. c
  374. go to 1001
  375. c .......... set error -- no convergence to a
  376. c singular value after 30 iterations ..........
  377. 1000 iarr = k
  378. 1001 return
  379. end
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  

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