正在加载图片...
7.6 Simple Monte Carlo Integration 305 Suppose that we pick N random points,uniformly distributed in a multidimen- sional volume V.Call them x1,...,xN.Then the basic theorem of Monte Carlo integration estimates the integral of a function f over the multidimensional volume. fdV≈V(f)士V f)-)2 (7.6.1) N Here the angle brackets denote taking the arithmetic mean over the N sample points, N (7.6.2) =1 The "plus-or-minus"term in(7.6.1)is a one standard deviation error estimate for the integral,not a rigorous bound;further,there is no guarantee that the error is distributed as a Gaussian.so the error term should be taken only as a rough indication of probable error. Suppose that you want to integrate a function g over a region W that is not easy to sample randomly.For example,W might have a very complicated shape. 2 No problem.Just find a region V that includes W and that can easily be sampled (Figure 7.6.1),and then define f to be equal to g for points in W and equal to zero for points outside of W(but still inside the sampled V).You want to try to make 豆。> Press. V enclose W as closely as possible,because the zero values of f will increase the error estimate term of(7.6.1).And well they should:points chosen outside of W have no information content,so the effective value of N,the number of points,is 9 reduced.The error estimate in (7.6.1)takes this into account. General purpose routines for Monte Carlo integration are quite complicated SCIENTIFIC( (see $7.8),but a worked example will show the underlying simplicity of the method. 61 Suppose that we want to find the weight and the position of the center of mass of an object of complicated shape,namely the intersection of a torus with the edge of a large box.In particular let the object be defined by the three simultaneous conditions 2+(2+乎-3)≤1 (7.6.3) 10-621 (torus centered on the origin with major radius =4,minor radius=2) 、NRO入 Numerical 43106 x21y2-3 (7.6.4) (two faces of the box,see Figure 7.6.2).Suppose for the moment that the object (outside has a constant density p. Software. We want to estimate the following integrals over the interior of the complicated North object: p dx dy dz xp dx dy dz yp dx dy dz zp dx dy dz (7.6.5) The coordinates of the center of mass will be the ratio of the latter three integrals (linear moments)to the first one (the weight). In the following fragment,the region V,enclosing the piece-of-torus W,is the rectangular box extending from I to 4 in z,-3 to 4 in y,and-1 to I in 2.7.6 Simple Monte Carlo Integration 305 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). Suppose that we pick N random points, uniformly distributed in a multidimen￾sional volume V . Call them x1,...,xN . Then the basic theorem of Monte Carlo integration estimates the integral of a function f over the multidimensional volume,  f dV ≈ V f ± V f 2−f 2 N (7.6.1) Here the angle brackets denote taking the arithmetic mean over the N sample points, f ≡ 1 N N i=1 f(xi)  f 2 ≡ 1 N N i=1 f 2(xi) (7.6.2) The “plus-or-minus” term in (7.6.1) is a one standard deviation error estimate for the integral, not a rigorous bound; further, there is no guarantee that the error is distributed as a Gaussian, so the error term should be taken only as a rough indication of probable error. Suppose that you want to integrate a function g over a region W that is not easy to sample randomly. For example, W might have a very complicated shape. No problem. Just find a region V that includes W and that can easily be sampled (Figure 7.6.1), and then define f to be equal to g for points in W and equal to zero for points outside of W (but still inside the sampled V ). You want to try to make V enclose W as closely as possible, because the zero values of f will increase the error estimate term of (7.6.1). And well they should: points chosen outside of W have no information content, so the effective value of N, the number of points, is reduced. The error estimate in (7.6.1) takes this into account. General purpose routines for Monte Carlo integration are quite complicated (see §7.8), but a worked example will show the underlying simplicity of the method. Suppose that we want to find the weight and the position of the center of mass of an object of complicated shape, namely the intersection of a torus with the edge of a large box. In particular let the object be defined by the three simultaneous conditions z2 + x2 + y2 − 3 2 ≤ 1 (7.6.3) (torus centered on the origin with major radius = 4, minor radius = 2) x ≥ 1 y ≥ −3 (7.6.4) (two faces of the box, see Figure 7.6.2). Suppose for the moment that the object has a constant density ρ. We want to estimate the following integrals over the interior of the complicated object:  ρ dx dy dz  xρ dx dy dz  yρ dx dy dz  zρ dx dy dz (7.6.5) The coordinates of the center of mass will be the ratio of the latter three integrals (linear moments) to the first one (the weight). In the following fragment, the region V , enclosing the piece-of-torus W, is the rectangular box extending from 1 to 4 in x, −3 to 4 in y, and −1 to 1 in z.
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有