c6-2 (779501)
Текст из файла
216Chapter 6.Special Functionswhich is related to the gamma function byB(z, w) =Γ(z)Γ(w)Γ(z + w)(6.1.9)#include <math.h>float beta(float z, float w)Returns the value of the beta function B(z, w).{float gammln(float xx);return exp(gammln(z)+gammln(w)-gammln(z+w));}CITED REFERENCES AND FURTHER READING:Abramowitz, M., and Stegun, I.A.
1964, Handbook of Mathematical Functions, Applied Mathematics Series, Volume 55 (Washington: National Bureau of Standards; reprinted 1968 byDover Publications, New York), Chapter 6.Lanczos, C. 1964, SIAM Journal on Numerical Analysis, ser. B, vol. 1, pp. 86–96. [1]6.2 Incomplete Gamma Function, ErrorFunction, Chi-Square Probability Function,Cumulative Poisson FunctionThe incomplete gamma function is defined by1γ(a, x)≡P (a, x) ≡Γ(a)Γ(a)Zxe−t ta−1 dt(a > 0)(6.2.1)0It has the limiting valuesP (a, 0) = 0P (a, ∞) = 1and(6.2.2)The incomplete gamma function P (a, x) is monotonic and (for a greater than one orso) rises from “near-zero”to “near-unity” in a range of x centered on about a − 1,√and of width about a (see Figure 6.2.1).The complement of P (a, x) is also confusingly called an incomplete gammafunction,Q(a, x) ≡ 1 − P (a, x) ≡1Γ(a, x)≡Γ(a)Γ(a)Z∞xe−t ta−1 dt(a > 0) (6.2.3)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).hence2176.2 Incomplete Gamma Function1.01.0.8a = 3.0.6a = 10.4.2002468101214xFigure 6.2.1.The incomplete gamma function P (a, x) for four values of a.It has the limiting valuesQ(a, 0) = 1andQ(a, ∞) = 0(6.2.4)The notations P (a, x), γ(a, x), and Γ(a, x) are standard; the notation Q(a, x) isspecific to this book.There is a series development for γ(a, x) as follows:γ(a, x) = e−x xa∞XΓ(a)xnΓ(a+1+n)n=0(6.2.5)One does not actually need to compute a new Γ(a + 1 + n) for each n; one ratheruses equation (6.1.3) and the previous coefficient.A continued fraction development for Γ(a, x) is1 1−a 1 2−a 2···(x > 0)(6.2.6)Γ(a, x) = e−x xax+ 1+ x+ 1+ x+It is computationally better to use the even part of (6.2.6), which converges twiceas fast (see §5.2):1 · (1 − a)2 · (2 − a)1···(x > 0)Γ(a, x) = e−x xax+1−a− x+3−a− x+5−a−(6.2.7)It turns out that (6.2.5) converges rapidly for x less than about a + 1, while(6.2.6) or (6.2.7) converges rapidly for x greater than about a + 1.
In these respectiveSample 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).incomplete gamma function P(a,x)0.5218Chapter 6.Special Functionsfloat gammp(float a, float x)Returns the incomplete gamma function P (a, x).{void gcf(float *gammcf, float a, float x, float *gln);void gser(float *gamser, float a, float x, float *gln);void nrerror(char error_text[]);float gamser,gammcf,gln;if (x < 0.0 || a <= 0.0) nrerror("Invalid arguments in routine gammp");if (x < (a+1.0)) {Use the series representation.gser(&gamser,a,x,&gln);return gamser;} else {Use the continued fraction representationgcf(&gammcf,a,x,&gln);return 1.0-gammcf;and take its complement.}}float gammq(float a, float x)Returns the incomplete gamma function Q(a, x) ≡ 1 − P (a, x).{void gcf(float *gammcf, float a, float x, float *gln);void gser(float *gamser, float a, float x, float *gln);void nrerror(char error_text[]);float gamser,gammcf,gln;if (x < 0.0 || a <= 0.0) nrerror("Invalid arguments in routine gammq");if (x < (a+1.0)) {Use the series representationgser(&gamser,a,x,&gln);return 1.0-gamser;and take its complement.} else {Use the continued fraction representation.gcf(&gammcf,a,x,&gln);return gammcf;}}The argument gln is set by both the series and continued fraction proceduresto the value ln Γ(a); the reason for this is so that it is available to you if you want tomodify the above two procedures to give γ(a, x) and Γ(a, x), in addition to P (a, x)and Q(a, x) (cf.
equations 6.2.1 and 6.2.3).The functions gser and gcf which implement (6.2.5) and (6.2.7) are#include <math.h>#define ITMAX 100#define EPS 3.0e-7void gser(float *gamser, float a, float x, float *gln)Returns the incomplete gamma function P (a, x) evaluated by its series representation as gamser.Also returns ln Γ(a) as gln.{float gammln(float xx);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).√regimes each requires at most a few times a terms to converge, and this manyonly near x = a, where the incomplete gamma functions are varying most rapidly.Thus (6.2.5) and (6.2.7) together allow evaluation of the function for all positivea and x.
An extra dividend is that we never need compute a function value nearzero by subtracting two nearly equal numbers. The higher-level functions that returnP (a, x) and Q(a, x) are6.2 Incomplete Gamma Function219void nrerror(char error_text[]);int n;float sum,del,ap;}#include <math.h>#define ITMAX 100#define EPS 3.0e-7#define FPMIN 1.0e-30Maximum allowed number of iterations.Relative accuracy.Number near the smallest representablefloating-point number.void gcf(float *gammcf, float a, float x, float *gln)Returns the incomplete gamma function Q(a, x) evaluated by its continued fraction representation as gammcf.
Also returns ln Γ(a) as gln.{float gammln(float xx);void nrerror(char error_text[]);int i;float an,b,c,d,del,h;*gln=gammln(a);b=x+1.0-a;Set up for evaluating continued fractionby modified Lentz’s method (§5.2)c=1.0/FPMIN;with b0 = 0.d=1.0/b;h=d;for (i=1;i<=ITMAX;i++) {Iterate to convergence.an = -i*(i-a);b += 2.0;d=an*d+b;if (fabs(d) < FPMIN) d=FPMIN;c=b+an/c;if (fabs(c) < FPMIN) c=FPMIN;d=1.0/d;del=d*c;h *= del;if (fabs(del-1.0) < EPS) break;}if (i > ITMAX) nrerror("a too large, ITMAX too small in gcf");*gammcf=exp(-x+a*log(x)-(*gln))*h;Put factors in front.}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).*gln=gammln(a);if (x <= 0.0) {if (x < 0.0) nrerror("x less than 0 in routine gser");*gamser=0.0;return;} else {ap=a;del=sum=1.0/a;for (n=1;n<=ITMAX;n++) {++ap;del *= x/ap;sum += del;if (fabs(del) < fabs(sum)*EPS) {*gamser=sum*exp(-x+a*log(x)-(*gln));return;}}nrerror("a too large, ITMAX too small in routine gser");return;}220Chapter 6.Special FunctionsError FunctionThe error function and complementary error function are special cases of theincomplete gamma function, and are obtained moderately efficiently by the aboveprocedures.
Their definitions areZxe−t dt2(6.2.8)0and2erfc(x) ≡ 1 − erf(x) = √πZ∞e−t dt2(6.2.9)xThe functions have the following limiting values and symmetries:erf(0) = 0erfc(0) = 1erf(∞) = 1erfc(∞) = 0erf(−x) = −erf(x)erfc(−x) = 2 − erfc(x)(6.2.10)(6.2.11)They are related to the incomplete gamma functions by1 2,x21 2erfc(x) = Q , x2erf(x) = Pand(x ≥ 0)(6.2.12)(x ≥ 0)(6.2.13)We’ll put an extra “f” into our routine names to avoid conflicts with names alreadyin some C libraries:float erff(float x)Returns the error function erf(x).{float gammp(float a, float x);return x < 0.0 ? -gammp(0.5,x*x) : gammp(0.5,x*x);}float erffc(float x)Returns the complementary error function erfc(x).{float gammp(float a, float x);float gammq(float a, float x);return x < 0.0 ? 1.0+gammp(0.5,x*x) : gammq(0.5,x*x);}If you care to do so, you √can easily remedy the minor inefficiency in erff anderffc, namely that Γ(0.5) = π is computed unnecessarily when gammp or gammqis called.
Before you do that, however, you might wish to consider the followingroutine, based on Chebyshev fitting to an inspired guess as to the functional form: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).2erf(x) = √π2216.2 Incomplete Gamma Function#include <math.h>float erfcc(float x)Returns the complementary error function erfc(x) with fractional error everywhere less than1.2 × 10−7 .{float t,z,ans;}There are also some functions of two variables that are special cases of theincomplete gamma function:Cumulative Poisson Probability FunctionPx (< k), for positive x and integer k ≥ 1, denotes the cumulative Poissonprobability function.
Характеристики
Тип файла PDF
PDF-формат наиболее широко используется для просмотра любого типа файлов на любом устройстве. В него можно сохранить документ, таблицы, презентацию, текст, чертежи, вычисления, графики и всё остальное, что можно показать на экране любого устройства. Именно его лучше всего использовать для печати.
Например, если Вам нужно распечатать чертёж из автокада, Вы сохраните чертёж на флешку, но будет ли автокад в пункте печати? А если будет, то нужная версия с нужными библиотеками? Именно для этого и нужен формат PDF - в нём точно будет показано верно вне зависимости от того, в какой программе создали PDF-файл и есть ли нужная программа для его просмотра.















