update.f 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. SUBROUTINE UPDATE (N,NPT,BMAT,ZMAT,NDIM,VLAG,BETA,DENOM,
  2. 1 KNEW,W)
  3. IMPLICIT REAL*8 (A-H,O-Z)
  4. DIMENSION BMAT(NDIM,*),ZMAT(NPT,*),VLAG(*),W(*)
  5. C
  6. C The arrays BMAT and ZMAT are updated, as required by the new position
  7. C of the interpolation point that has the index KNEW. The vector VLAG has
  8. C N+NPT components, set on entry to the first NPT and last N components
  9. C of the product Hw in equation (4.11) of the Powell (2006) paper on
  10. C NEWUOA. Further, BETA is set on entry to the value of the parameter
  11. C with that name, and DENOM is set to the denominator of the updating
  12. C formula. Elements of ZMAT may be treated as zero if their moduli are
  13. C at most ZTEST. The first NDIM elements of W are used for working space.
  14. C
  15. C Set some constants.
  16. C
  17. ONE=1.0D0
  18. ZERO=0.0D0
  19. NPTM=NPT-N-1
  20. ZTEST=ZERO
  21. DO 10 K=1,NPT
  22. DO 10 J=1,NPTM
  23. 10 ZTEST=DMAX1(ZTEST,DABS(ZMAT(K,J)))
  24. ZTEST=1.0D-20*ZTEST
  25. C
  26. C Apply the rotations that put zeros in the KNEW-th row of ZMAT.
  27. C
  28. JL=1
  29. DO 30 J=2,NPTM
  30. IF (DABS(ZMAT(KNEW,J)) .GT. ZTEST) THEN
  31. TEMP=DSQRT(ZMAT(KNEW,1)**2+ZMAT(KNEW,J)**2)
  32. TEMPA=ZMAT(KNEW,1)/TEMP
  33. TEMPB=ZMAT(KNEW,J)/TEMP
  34. DO 20 I=1,NPT
  35. TEMP=TEMPA*ZMAT(I,1)+TEMPB*ZMAT(I,J)
  36. ZMAT(I,J)=TEMPA*ZMAT(I,J)-TEMPB*ZMAT(I,1)
  37. 20 ZMAT(I,1)=TEMP
  38. END IF
  39. ZMAT(KNEW,J)=ZERO
  40. 30 CONTINUE
  41. C
  42. C Put the first NPT components of the KNEW-th column of HLAG into W,
  43. C and calculate the parameters of the updating formula.
  44. C
  45. DO 40 I=1,NPT
  46. W(I)=ZMAT(KNEW,1)*ZMAT(I,1)
  47. 40 CONTINUE
  48. ALPHA=W(KNEW)
  49. TAU=VLAG(KNEW)
  50. VLAG(KNEW)=VLAG(KNEW)-ONE
  51. C
  52. C Complete the updating of ZMAT.
  53. C
  54. TEMP=DSQRT(DENOM)
  55. TEMPB=ZMAT(KNEW,1)/TEMP
  56. TEMPA=TAU/TEMP
  57. DO 50 I=1,NPT
  58. 50 ZMAT(I,1)=TEMPA*ZMAT(I,1)-TEMPB*VLAG(I)
  59. C
  60. C Finally, update the matrix BMAT.
  61. C
  62. DO 60 J=1,N
  63. JP=NPT+J
  64. W(JP)=BMAT(KNEW,J)
  65. TEMPA=(ALPHA*VLAG(JP)-TAU*W(JP))/DENOM
  66. TEMPB=(-BETA*W(JP)-TAU*VLAG(JP))/DENOM
  67. DO 60 I=1,JP
  68. BMAT(I,J)=BMAT(I,J)+TEMPA*VLAG(I)+TEMPB*W(I)
  69. IF (I .GT. NPT) BMAT(JP,I-NPT)=BMAT(I,J)
  70. 60 CONTINUE
  71. RETURN
  72. END