Télécharger dqrls.eso

Retour à la liste

Numérotation des lignes :

dqrls
  1. C DQRLS SOURCE PV090527 23/02/07 11:58:37 11592
  2. subroutine dqrls ( a, lda, m, n, tol, kr, b, x,r,jpvt,qraux,work,
  3. # itask, ind )
  4.  
  5. c*****************************************************************************80
  6. c
  7. c! DQRLS factors and solves a linear system in the least squares sense.
  8. c
  9. c Discussion:
  10. c
  11. c The linear system may be overdetermined, underdetermined or singular.
  12. c The solution is obtained using a QR factorization of the
  13. c coefficient matrix.
  14. c
  15. c DQRLS can be efficiently used to solve several least squares
  16. c problems with the same matrix A. The first system is solved
  17. c with ITASK = 1. The subsequent systems are solved with
  18. c ITASK = 2, to avoid the recomputation of the matrix factors.
  19. c The parameters KR, JPVT, and QRAUX must not be modified
  20. c between calls to DQRLS.
  21. c
  22. c DQRLS is used to solve in a least squares sense
  23. c overdetermined, underdetermined and singular linear systems.
  24. c The system is A*X approximates B where A is M by N.
  25. c B is a given M-vector, and X is the N-vector to be computed.
  26. c A solution X is found which minimimzes the sum of squares (2-norm)
  27. c of the residual, A*X - B.
  28. c
  29. c The numerical rank of A is determined using the tolerance TOL.
  30. c
  31. c DQRLS uses the LINPACK subroutine DQRDC to compute the QR
  32. c factorization, with column pivoting, of an M by N matrix A.
  33. c
  34. c Modified:
  35. c
  36. c 15 April 2012
  37. c
  38. c Reference:
  39. c
  40. c David Kahaner, Cleve Moler, Steven Nash,
  41. c Numerical Methods and Software,
  42. c Prentice Hall, 1989,
  43. c ISBN: 0-13-627258-4,
  44. c LC: TA345.K34.
  45. c
  46. c Parameters:
  47. c
  48. c Input/output, real*8 A(LDA,N), an M by N matrix.
  49. c On input, the matrix whose decomposition is to be computed.
  50. c In a least squares data fitting problem, A(I,J) is the
  51. c value of the J-th basis (model) function at the I-th data point.
  52. c On output, A contains the output from DQRDC. The triangular matrix R
  53. c of the QR factorization is contained in the upper triangle and
  54. c information needed to recover the orthogonal matrix Q is stored
  55. c below the diagonal in A and in the vector QRAUX.
  56. c
  57. c Input, integer LDA, the leading dimension of A.
  58. c
  59. c Input, integer M, the number of rows of A.
  60. c
  61. c Input, integer N, the number of columns of A.
  62. c
  63. c Input, real*8 TOL, a relative tolerance used to determine the
  64. c numerical rank. The problem should be scaled so that all the elements
  65. c of A have roughly the same absolute accuracy EPS. Then a reasonable
  66. c value for TOL is roughly EPS divided by the magnitude of the largest
  67. c element.
  68. c
  69. c Output, integer KR, the numerical rank.
  70. c
  71. c Input, real*8 B(M), the right hand side of the linear system.
  72. c
  73. c Output, real*8 X(N), a least squares solution to the linear
  74. c system.
  75. c
  76. c Output, real*8 R(M), the residual, B - A*X. R may
  77. c overwrite B.
  78. c
  79. c Workspace, integer JPVT(N), required if ITASK = 1.
  80. c Columns JPVT(1), ..., JPVT(KR) of the original matrix are linearly
  81. c independent to within the tolerance TOL and the remaining columns
  82. c are linearly dependent. ABS ( A(1,1) ) / ABS ( A(KR,KR) ) is an estimate
  83. c of the condition number of the matrix of independent columns,
  84. c and of R. This estimate will be .le. 1/TOL.
  85. c
  86. c Workspace, real*8 QRAUX(N), required if ITASK = 1.
  87. c
  88. c Workspace, real*8 WORK(N), required if ITASK = 1.
  89. c
  90. c Input, integer ITASK.
  91. c 1, DQRLS factors the matrix A and solves the least squares problem.
  92. c 2, DQRLS assumes that the matrix A was factored with an earlier
  93. c call to DQRLS, and only solves the least squares problem.
  94. c
  95. c Output, integer IND, error code.
  96. c 0: no error
  97. c -1: LDA .lt. M (fatal error)
  98. c -2: N .lt. 1 (fatal error)
  99. c -3: ITASK .lt. 1 (fatal error)
  100. c
  101. implicit real*8 (a-h,o-z)
  102. implicit integer (i-n)
  103.  
  104. integer lda
  105. integer m
  106. integer n
  107.  
  108. real*8 a(lda,n)
  109. real*8 b(m)
  110. integer ind
  111. integer itask
  112. integer jpvt(n)
  113. integer kr
  114. real*8 qraux(n)
  115. real*8 r(m)
  116. real*8 tol
  117. real*8 work(n)
  118. real*8 x(n)
  119.  
  120. if ( lda .lt. m ) then
  121. write ( *, '(a)' ) ' '
  122. write ( *, '(a)' ) 'DQRLS - Fatal error!'
  123. write ( *, '(a)' ) ' LDA .lt. M.'
  124. stop
  125. end if
  126.  
  127. if ( n .le. 0 ) then
  128. write ( *, '(a)' ) ' '
  129. write ( *, '(a)' ) 'DQRLS - Fatal error!'
  130. write ( *, '(a)' ) ' N .le. 0.'
  131. stop
  132. end if
  133.  
  134. if ( itask .lt. 1 ) then
  135. write ( *, '(a)' ) ' '
  136. write ( *, '(a)' ) 'DQRLS - Fatal error!'
  137. write ( *, '(a)' ) ' ITASK .lt. 1.'
  138. stop
  139. end if
  140.  
  141. ind = 0
  142.  
  143. c Factor the matrix.
  144.  
  145. if ( itask .eq. 1 ) then
  146. call dqrank ( a, lda, m, n, tol, kr, jpvt, qraux, work )
  147. end if
  148.  
  149. c Solve the least-squares problem.
  150.  
  151. call dqrlss ( a, lda, m, n, kr, b, x, r, jpvt, qraux )
  152.  
  153. return
  154. end
  155.  
  156.  

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