正在加载图片...
680 Chapter 15.Modeling of Data void fpoly(float x,float p[],int np) Fitting routine for a polynomial of degree np-1,with coefficients in the array p[1..np]. int ji p[1]=1.0: for (j=2;j<=mp;j++)p[j]=p[j-1]*x; The second example is slightly less trivial.It is used to fit Legendre polynomials up to some order nl-1 through a data set. void fleg(float x,float pl[],int nl) Fitting routine for an expansion with nl Legendre polynomials pl,evaluated using the recurrence 19881992 relation as in $5.5. from NUMERICAL int j; float twox,f2,f1,d; p1[1]=1.0; to any p1[2]x: RECIPES if(n1>2)[ twox=2.0*x; f2=x; d=1.0: server computer, (North America University Press. THE for (j=3;j<=nl;j++){ make one paper f1=d++; ART f2 +tvox; p1[j]=(f2*p1[j-1]-f1*p1[j-2])/d; strictly proh Programs 22 to dir Multidimensional Fits OF SCIENTIFIC COMPUTING(ISBN If you are measuring a single variable y as a function of more than one variable 17881992b -say,a vector of variables x,then your basis functions will be functions of a vector, X(x),...,X(x).The x2 merit function is now Numerical 10-621 k1akXk(x)》 43108 (15.4.24) 0 All of the preceding discussion goes through unchanged,with x replaced by x.In (outside Recipes fact,if you are willing to tolerate a bit of programming hack,you can use the above North Software. programs without any modification:In both lfit and svdfit,the only use made of the array elementsx[i]is that each element is in turn passed to the user-supplied routine funcs,which duly gives back the values of the basis functions at that point. If you set x[i]=i before calling lfit or svdfit,and independently provide funcs machine with the true vector values of your data points(e.g.,in global variables),then funcs can translate from the fictitious x [i]'s to the actual data points before doing its work. CITED REFERENCES AND FURTHER READING: Bevington,P.R.1969,Data Reduction and Error Analysis for the Physical Sciences (New York: McGraw-Hill),Chapters 8-9.680 Chapter 15. Modeling of Data Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machine￾readable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). void fpoly(float x, float p[], int np) Fitting routine for a polynomial of degree np-1, with coefficients in the array p[1..np]. { int j; p[1]=1.0; for (j=2;j<=np;j++) p[j]=p[j-1]*x; } The second example is slightly less trivial. It is used to fit Legendre polynomials up to some order nl-1 through a data set. void fleg(float x, float pl[], int nl) Fitting routine for an expansion with nl Legendre polynomials pl, evaluated using the recurrence relation as in §5.5. { int j; float twox,f2,f1,d; pl[1]=1.0; pl[2]=x; if (nl > 2) { twox=2.0*x; f2=x; d=1.0; for (j=3;j<=nl;j++) { f1=d++; f2 += twox; pl[j]=(f2*pl[j-1]-f1*pl[j-2])/d; } } } Multidimensional Fits If you are measuring a single variable y as a function of more than one variable — say, a vector of variables x, then your basis functions will be functions of a vector, X1(x),...,XM(x). The χ2 merit function is now χ2 =  N i=1 yi − M k=1 akXk(xi) σi 2 (15.4.24) All of the preceding discussion goes through unchanged, with x replaced by x. In fact, if you are willing to tolerate a bit of programming hack, you can use the above programs without any modification: In both lfit and svdfit, the only use made of the array elements x[i] is that each element is in turn passed to the user-supplied routine funcs, which duly gives back the values of the basis functions at that point. If you set x[i]=i before calling lfit or svdfit, and independently provide funcs with the true vector values of your data points (e.g., in global variables), then funcs can translate from the fictitious x[i]’s to the actual data points before doing its work. CITED REFERENCES AND FURTHER READING: Bevington, P.R. 1969, Data Reduction and Error Analysis for the Physical Sciences (New York: McGraw-Hill), Chapters 8–9.
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有