Code and documentation for some of this using a Gaussian weight is in extr.zip. Extensive use is made of the notion of passing references to arrays of the form CALL WINVS(WF(NB),WFINV(NB)) There were some problems that seem to have gone away. I found documentation in Watcom’s fbooks.hlp for this method, but may have made some subtle error. The current code in which the error does not appear is in ..\Progdet\ArrayPass\ArrayPass.doc. Extending R – originally in Periodic W.doc – code in This begins with the Newton Raphson equation ..\..\Fittery\Complex\WeightedFourierFit\WeightedFourierFit.doc#NReqn which can be summarized as R m ME W m n X n nM B MB m ME Define M Range M E M B 1 (1.2) M mid M Range / 2 (1.3) (1.1) So that (1.1) can be written M Range / 2 1 n M Range / 2 W m n X n M mid R m M mid M Range / 2 m M Ramge / 2 (1.4) For sufficiently small ME-MB+1, equations (1.4) are best solved as an array of equations. 1 W m n X n R m m 2,1 n 2 (1.5) W [2 2] W [2 1] W [2 0] W [ 2 1] X 2 M mid R 2 M mid W [1 2] W [1 1] W [1 0] W [ 1 1] X 1 M R 1 M mid mid X 0 M W [0 2] W [0 1] W [0 0] W [0 1] mid R 0 M mid W [1 2] W [1 1] W [1 0] W [1 1] X 1 M mid R 1 M mid (1.6) Or W [0] W [1] W [2] W [3] X 2 M mid R 2 M mid W [1] W [0] W [ 1] W [ 2] X 1 M R 1 M mid mid (1.7) X 0 M R 0 M W [2] W [1] W [0] W [ 1] mid mid W [3] W [2] W [1] W [0] X 1 M mid R 1 M mid -1 The code in winvs.doc finds W such that Mp / 21 m Mp / 2 W 1 k m W m n k ,n In this case Mp/2-1≥3 The code for\extr\extr.wpj begins with Mmid = 0. Note that -2, to 1 for 4 points requires -3, to 3 for 7 terms. In general this requirement is from –Mp/2-(Mp/2-1)=-Mp-1 to Mp/2-1-(-Mp/2) = Mp-1. This is one less than doubling the size. In particular, Mfit in the above example is 4 with points from 2, to 1, while Mp is 8 with points from -4 to 3. The value of W[-4] is undefined. A reasonable estimate for this value is W M fit 1 W M fit 1 (1.8) W M fit 2 The values of W in (1.5) and (1.7) range from W[-3] through W[3]. These are Fourier transforms of the weights for the various values of t T N / 21 mi W m w i exp j 2 (1.9) 3 m 3 N i N / 2 N MRange is defined in (1.2). Note that W is used in (1.5) and (1.7) for values from – (MRange-1)/2 to (MRamge-1)/2. Extend the matrix in (1.4) by defining Note that the point at -4 is undefined. The extended range will always have at least one such point since the W matrix is from –(ME-MB) to ME-MB which counting zero has an odd number of terms while the periodic matrix always goes from –Mp/2 to Mp/2-1 which is an even number of terms. for\winvs\twinvs.wpj 0 n M Range / 2 X p n M mid X n M mid M Range / 2 n M Range / 2 (1.10) 0 n M Range / 2 M p M R M sup (1.11) Where Msup is any positive value needed to make MBlock a convenient size. W’s for the regions -Mp/2 m < MB and ME < m < Mp can be set equal to any values. Define W n M p n M p / 2 Wp n W n M p / 2 m M p / 2 (1.12) n Mp /2 W n M p The matrix Wp is periodic with period Mp. This means that what can be defined by M / 2 1 1 p mi W m exp j 2 (1.13) T m M p / 2 M p The orthonormality of the exponential sum means that M p / 2 1 T mi W m wˆ i exp j 2 (1.14) M p i M p / 2 M p wˆ i So that Periodic W.doc (1.16) becomes M p / 2 1 T 1 mi ' 1 Wp m exp j 2 (1.15) M p i ' M p / 2 T 2 wˆ i M p Multiply (1.4) by W-1[k-m] and sum m from –Mp/2 to Mp/2-1 ME M p / 2 1 n M B m M p / 2 Wp 1 M p / 2 1 k mWp m nX n M mid m M p / 2 Wp 1 k m R m M mid (1.16) Or X k M mid M p / 2 1 m M p / 2 W 1 k m R m M mid M p / 2 k M p / 2 (1.17) There is a problem with (1.17). The R[m]’s are defined only for MB m ME. In addition this produces X’s outside the –MRange/2 to MRange /2 region. On the first iteration take 0 m M Range / 2 N / 21 m M mid i T R1 m M mid w i d i d A ti ; DA exp j 2 M Range / 2 m M Range / 2 N N i N / 2 0 m M Range / 2 (1.18) Use (1.17) to find values of X for MB m ME so that X it n M mid M p / 2 1 m M p / 2 W 1 n m Rit m M mid M p / 2 m M p / 2 (1.19) Then define Rit 1 m M p / 2 1 n M p / 2 W m n X it n (1.20) The method is 1. Use (1.13) and (1.15) to find W-1 over the region –MBlock-1 to MBlock 2. Use (1.18) for the values or R only in the region MB m ME. For other regions set R[m] = 0. (Diagonal approximation.doc) Use (1.19) to find Xit 3. Use (1.20) to find Rit+1[m] for –Mp/2 m<MB and ME<m< Mp/2-1 4. Go to 3 if not converged. All steps are Fourier transforms or convolutions. These require Mp log2(Mp) operations. Solution of the matrix in Periodic W.doc (1.5) requires (ME-MB+1)3/3 operations. Even with ME-MB+1 as small as 10 the iteration requirement is ~ 100 operations per iteration while the matrix inverse is on the order of 300 operations. As a minimization problem define M Range / 2 1 2 R X m M mid , R M Range / 2 1 2 M p / 2 Mp /2 X 2 m M mid , R (1.21) There is a separate undefined R[m] for every term in (1.21). It is not at all certain that steps 1 through 5 will find the R’s needed for this convergence, but it is probable. If this convergence is found, the X’s explicitly solve (1.4). Chi-square Define Mfit / 21 X 0 m 02 n Mfit / 2 m M B m M E W 1 m nR n M p / 2 m M p / 2 X 0 m X 0 m (2.1) (2.2) Equation (2.1) uses only the original set of R’s defined between –Nfit/2 and Nfit/2-1. The term X0 is defined for all values of m. The rest of the R’s are defined by Mfit / 2 1 m N fit / 2 (2.3) Ri m W m nX i 1 n n Mfit / 2 m N fit / 2 Mp / 21 X i m n Mp / 2 Mfit / 21 X ti m i2 W 1 Ri m X 0 m X ti m m M B mM E W 1 n Mp / 2 Mp / 2 1 m n Ri n X i m X i m n Mfit / 2 (2.4) W 1 m n Ri n (2.5) (2.6) Form a summation set of Ri’s m N fit / 2 R fit m di Ri m i m N fit / 2 Where di = I + j X fit [m] X 0 m di i W n m R n 1 n M B nM E p i X 0 m di X ti m i Then 2 d X 0 m di X ti m X 0 m d i X ti m m M B i i mM E Set the derivative with respect to k equal to zero. (2.7) 2 X 0 m di X ti m X tk m c.c. k m M B i (2.8) m M E And the derivative with respect to k equal to zero 2 X 0 m di X ti m X tk m c.c. k m M B i (2.9) m M E Equation (2.8) is twice the real part of the first term, while (2.9) is twice the real imaginary part of the first term. Multiply 2.9 by j and add it to 2.8 to form 2 2 (2.10) j 2 X 0 m di X ti m X tk m k k m M B i m M E The complex derivative in (2.10) is zero when both (2.8) and (2.9) are satisfied. Define the complex matrices A and B (2.11) Bk X 0 mX tk m m M B mM E And Ai ,k m M B mM E X ti mX tk m (2.12) The array A i,k is not exactly symmetric, Ak,i = A*i,k. The equation for the dk’s is (2.13) di Ai,k Bk i This may seem to have come full circle in solving a matrix equation for the d’s that is formally similar to the original, but there are only a few terms in Error! Reference source not found. whose purpose is to handle over-relaxation and to control the iteration procedure. The vectors R