sods.f 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. *DECK SODS
  2. SUBROUTINE SODS (A, X, B, NEQ, NUK, NRDA, IFLAG, WORK, IWORK)
  3. C***BEGIN PROLOGUE SODS
  4. C***SUBSIDIARY
  5. C***PURPOSE Subsidiary to BVSUP
  6. C***LIBRARY SLATEC
  7. C***TYPE SINGLE PRECISION (SODS-S)
  8. C***AUTHOR Watts, H. A., (SNLA)
  9. C***DESCRIPTION
  10. C
  11. C SODS solves the overdetermined system of linear equations A X = B,
  12. C where A is NEQ by NUK and NEQ .GE. NUK. If rank A = NUK,
  13. C X is the UNIQUE least squares solution vector. That is,
  14. C R(1)**2 + ..... + R(NEQ)**2 = minimum
  15. C where R is the residual vector R = B - A X.
  16. C If rank A .LT. NUK , the least squares solution of minimal
  17. C length can be provided.
  18. C SODS is an interfacing routine which calls subroutine LSSODS
  19. C for the solution. LSSODS in turn calls subroutine ORTHOL and
  20. C possibly subroutine OHTROR for the decomposition of A by
  21. C orthogonal transformations. In the process, ORTHOL calls upon
  22. C subroutine CSCALE for scaling.
  23. C
  24. C **********************************************************************
  25. C Input
  26. C **********************************************************************
  27. C
  28. C A -- Contains the matrix of NEQ equations in NUK unknowns and must
  29. C be dimensioned NRDA by NUK. The original A is destroyed
  30. C X -- Solution array of length at least NUK
  31. C B -- Given constant vector of length NEQ, B is destroyed
  32. C NEQ -- Number of equations, NEQ greater or equal to 1
  33. C NUK -- Number of columns in the matrix (which is also the number
  34. C of unknowns), NUK not larger than NEQ
  35. C NRDA -- Row dimension of A, NRDA greater or equal to NEQ
  36. C IFLAG -- Status indicator
  37. C =0 For the first call (and for each new problem defined by
  38. C a new matrix A) when the matrix data is treated as exact
  39. C =-K For the first call (and for each new problem defined by
  40. C a new matrix A) when the matrix data is assumed to be
  41. C accurate to about K digits
  42. C =1 For subsequent calls whenever the matrix A has already
  43. C been decomposed (problems with new vectors B but
  44. C same matrix a can be handled efficiently)
  45. C WORK(*),IWORK(*) -- Arrays for storage of internal information,
  46. C WORK must be dimensioned at least 2 + 5*NUK
  47. C IWORK must be dimensioned at least NUK+2
  48. C IWORK(2) -- Scaling indicator
  49. C =-1 If the matrix A is to be pre-scaled by
  50. C columns when appropriate
  51. C If the scaling indicator is not equal to -1
  52. C no scaling will be attempted
  53. C For most problems scaling will probably not be necessary
  54. C
  55. C **********************************************************************
  56. C OUTPUT
  57. C **********************************************************************
  58. C
  59. C IFLAG -- Status indicator
  60. C =1 If solution was obtained
  61. C =2 If improper input is detected
  62. C =3 If rank of matrix is less than NUK
  63. C If the minimal length least squares solution is
  64. C desired, simply reset IFLAG=1 and call the code again
  65. C X -- Least squares solution of A X = B
  66. C A -- Contains the strictly upper triangular part of the reduced
  67. C matrix and the transformation information
  68. C WORK(*),IWORK(*) -- Contains information needed on subsequent
  69. C Calls (IFLAG=1 case on input) which must not
  70. C be altered
  71. C WORK(1) contains the Euclidean norm of
  72. C the residual vector
  73. C WORK(2) contains the Euclidean norm of
  74. C the solution vector
  75. C IWORK(1) contains the numerically determined
  76. C rank of the matrix A
  77. C
  78. C **********************************************************************
  79. C
  80. C***SEE ALSO BVSUP
  81. C***REFERENCES G. Golub, Numerical methods for solving linear least
  82. C squares problems, Numerische Mathematik 7, (1965),
  83. C pp. 206-216.
  84. C P. Businger and G. Golub, Linear least squares
  85. C solutions by Householder transformations, Numerische
  86. C Mathematik 7, (1965), pp. 269-276.
  87. C H. A. Watts, Solving linear least squares problems
  88. C using SODS/SUDS/CODS, Sandia Report SAND77-0683,
  89. C Sandia Laboratories, 1977.
  90. C***ROUTINES CALLED LSSODS
  91. C***REVISION HISTORY (YYMMDD)
  92. C 750601 DATE WRITTEN
  93. C 890831 Modified array declarations. (WRB)
  94. C 891214 Prologue converted to Version 4.0 format. (BAB)
  95. C 900402 Added TYPE section. (WRB)
  96. C 910408 Updated the AUTHOR and REFERENCES sections. (WRB)
  97. C 920501 Reformatted the REFERENCES section. (WRB)
  98. C***END PROLOGUE SODS
  99. DIMENSION A(NRDA,*),X(*),B(*),WORK(*),IWORK(*)
  100. C
  101. C***FIRST EXECUTABLE STATEMENT SODS
  102. ITER=0
  103. IS=2
  104. IP=3
  105. KS=2
  106. KD=3
  107. KZ=KD+NUK
  108. KV=KZ+NUK
  109. KT=KV+NUK
  110. KC=KT+NUK
  111. C
  112. CALL LSSODS(A,X,B,NEQ,NUK,NRDA,IFLAG,IWORK(1),IWORK(IS),A,
  113. 1 WORK(KD),IWORK(IP),ITER,WORK(1),WORK(KS),
  114. 2 WORK(KZ),B,WORK(KV),WORK(KT),WORK(KC))
  115. C
  116. RETURN
  117. END