Appendix C Weighted Least Squares Fit by Iteration1 In general we have N evenly spaced values dj and wj. We want to find a smooth function f(x,a) where a contains M parameters such that w2 d j f x j , a / w j 2 (27) j is minimal with respect to the parameters in a, We anticipate that the N will be as large as 4096 and that N will be as large as 400. In the special case where all of the wj’s are equal, it is possible to take advantage of the orthogonality of the cosine series to expand f(x) as a cosine series for which the number of operations is proportional to only N*M rather than N*M3 since there is no need to invert a matrix. The number of operations for large M is further reduced and the ability to represent the data improved by extending the data from N points to an even power of 2, N2 by repeating the average of the last 10 points and reflecting the dj’s by defining d j N 2 d N 2 j 1 (28) This makes the data look reasonably periodic and allows N coefficients in the series to be found using the Cooley-Tukey fast Fourier transform and a number of operations proportional to N2 log2 (N2). Using the first M coefficients in this series yields M f x ak cos kx / N 2 (29) k 0 which minimizes Eq. 27 for M coefficients with all wj’s equal. Note that the fast Fourier transform in reverse of the truncated series yields f(xj) for the evenly spaced set of xj values. After the first estimate a term j d j f x j / w / wj (30) is defined and a least squares fit made minimizing e2 j x j , a 2 (31) j with respect to the parameters ak again by truncating the Fourier transform. The ak’s in Equation 29 are then updated by adding the ak to redefine f(x) which is again recovered by the reverse transform. The process is iterated until (x,a) is essentially zero, at which point Eqns. 31 and 27 are to within a constant the same, thus the final values of ak minimize Eqn. 27 as desired. 1 "RLCFIT: An Iterative Spectrum Analysis Code", R.L. Coldwell, Radiative Properties of Hot Dense Matter, Edited by J. Davis, C.F. Hooper Jr., R. Lee, A. Merts and B. Rozsnyai (World Scientific, Singapore, 1985) pp. 315. – Appendix C.