Page - 85 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python
Image of the Page - 85 -
Text of the Page - 85 -
3.7 DoubleandTriple Integrals 85
boundaryg D 0 as the zero-level contourof the level-set function. For simple ge-
ometries onecan easily constructg byhand,while inmorecomplicated industrial
applicationsonemust resort tomathematicalmodels forconstructingg.
LetA.˝/be theareaofadomain˝.Wecanestimate the integralbythisMonte
Carlo integrationmethod:
1. embed thegeometry˝ in a rectangularareaR
2. drawa largenumberof randompoints .x;y/ inR
3. count the fractionqofpoints that are inside˝
4. approximateA.˝/=A.R/byq, i.e., setA.˝/DqA.R/
5. evaluate themeanoff , Nf , at thepoints inside˝
6. estimate the integral asA.˝/
Nf
NotethatA.R/ is trivial tocomputesinceR isarectangle,whileA.˝/ isunknown.
However, ifweassume that the fractionofA.R/occupiedbyA.˝/ is the sameas
the fractionof randompoints inside˝,wegeta simpleestimate forA.˝/.
Toget an ideaof themethod,consider acirculardomain˝ embedded ina rect-
angleas shownbelow.Acollectionof randompoints is illustratedbyblackdots.
Implementation APythonfunctionimplementing R
˝ f.x;y/dxdy canbewritten
like this:
import numpy as np
def MonteCarlo_double(f, g, x0, x1, y0, y1, n):
"""
Monte Carlo integration of f over a domain g>=0, embedded
in a rectangle [x0,x1]x[y0,y1]. n^2 is the number of
random points.
"""
back to the
book Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python"
Programming for Computations – Python
A Gentle Introduction to Numerical Simulations with Python
- Title
- Programming for Computations – Python
- Subtitle
- A Gentle Introduction to Numerical Simulations with Python
- Authors
- Svein Linge
- Hans Petter Langtangen
- Publisher
- Springer Open
- Date
- 2016
- Language
- English
- License
- CC BY-NC 4.0
- ISBN
- 978-3-319-32428-9
- Size
- 17.8 x 25.4 cm
- Pages
- 248
- Keywords
- Programmiersprache, Informatik, programming language, functional, imperative, object-oriented, reflective
- Category
- Informatik