c15-2 (779586), страница 2
Текст из файла (страница 2)
Further reproduction, or any copying of machinereadable files (including this one) to any servercomputer, is strictly prohibited. To order Numerical Recipes books,diskettes, or CDROMsvisit website http://www.nr.com or call 1-800-872-7423 (North America only),or send email to trade@cup.cam.ac.uk (outside North America).S211+ xSSStt1σb2 =SttSxCov(a, b) = −SSttCov(a, b)rab =σa σbσa2 =666Chapter 15.Modeling of Data}CITED REFERENCES AND FURTHER READING:Bevington, P.R. 1969, Data Reduction and Error Analysis for the Physical Sciences (New York:McGraw-Hill), Chapter 6.15.3 Straight-Line Data with Errors in BothCoordinatesIf experimental data are subject to measurement error not only in the yi ’s, but also inthe xi ’s, then the task of fitting a straight-line modely(x) = a + bx(15.3.1)2is considerably harder.
It is straightforward to write down the χ merit function for this case,χ2 (a, b) =NX(yi − a − bxi )2i=1σy2 i + b2 σx2 i(15.3.2)where σx i and σy i are, respectively, the x and y standard deviations for the ith point. Theweighted sum of variances in the denominator of equation (15.3.2) can be understood bothas the variance in the direction of the smallest χ2 between each data point and the line withslope b, and also as the variance of the linear combination yi − a − bxi of two randomvariables xi and yi ,Var(yi − a − bxi ) = Var(yi ) + b2 Var(xi ) = σy2 i + b2 σx2 i ≡ 1/wi(15.3.3)The sum of the square of N random variables, each normalized by its variance, is thusχ2 -distributed.We want to minimize equation (15.3.2) with respect to a and b.
Unfortunately, theoccurrence of b in the denominator of equation (15.3.2) makes the resulting equation forthe slope ∂χ2 /∂b = 0 nonlinear. However, the corresponding condition for the intercept,∂χ2 /∂a = 0, is still linear and yields"#,XXa=wi (yi − bxi )wi(15.3.4)iiwhere the wi ’s are defined by equation (15.3.3). A reasonable strategy, now, is to use themachinery of Chapter 10 (e.g., the routine brent) for minimizing a general one-dimensionalfunction to minimize with respect to b, while using equation (15.3.4) at each stage to ensurethat the minimum with respect to b is also minimized with respect to a.Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5)Copyright (C) 1988-1992 by Cambridge University Press.Programs Copyright (C) 1988-1992 by Numerical Recipes Software.Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copying of machinereadable files (including this one) to any servercomputer, is strictly prohibited.
To order Numerical Recipes books,diskettes, or CDROMsvisit website http://www.nr.com or call 1-800-872-7423 (North America only),or send email to trade@cup.cam.ac.uk (outside North America).*chi2=0.0;Calculate χ2 .*q=1.0;if (mwt == 0) {for (i=1;i<=ndata;i++)*chi2 += SQR(y[i]-(*a)-(*b)*x[i]);sigdat=sqrt((*chi2)/(ndata-2));For unweighted data evaluate typ*siga *= sigdat;ical sig using chi2, and ad*sigb *= sigdat;just the standard deviations.} else {for (i=1;i<=ndata;i++)*chi2 += SQR((y[i]-(*a)-(*b)*x[i])/sig[i]);if (ndata>2) *q=gammq(0.5*(ndata-2),0.5*(*chi2));Equation (15.2.12).}.















