Web-Books
in the Austria-Forum
Austria-Forum
Web-Books
Informatik
Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition
Page - 165 -
  • User
  • Version
    • full version
    • text only version
  • Language
    • Deutsch - German
    • English

Page - 165 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition

Image of the Page - 165 -

Image of the Page - 165 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition

Text of the Page - 165 -

6.7 DoubleandTriple Integrals 165 3. count the fractionq ofpoints that are insideΩ 4. approximateA(Ω)/A(R)byq, i.e., setA(Ω)=qA(R) 5. evaluate themeanoff , f¯ , at thepoints insideΩ 6. estimate the integralasA(Ω)f¯ Note that A(R) is trivial to compute since R is a rectangle, while A(Ω) is unknown. However, if we assume that the fraction ofA(R) occupied byA(Ω) is the same as the fraction of random points insideΩ, we get a simple estimate for A(Ω). To get an idea of the method, consider a circular domain Ω embedded in a rectangle as shown below. A collection of random points is illustrated by black dots. Implementation APythonfunctionimplementing ∫ Ωf(x,y)dxdycanbewritten 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. """ # Draw n**2 random points in the rectangle x = np.random.uniform(x0, x1, n) y = np.random.uniform(y0, y1, n) # Compute sum of f values inside the integration domain f_mean = 0 num_inside = 0 # number of x,y points inside domain (g>=0) for i in range(len(x)): for j in range(len(y)): if g(x[i], y[j]) >= 0: num_inside = num_inside + 1
back to the  book Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition"
Programming for Computations – Python A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition
Title
Programming for Computations – Python
Subtitle
A Gentle Introduction to Numerical Simulations with Python 3.6
Volume
Second Edition
Authors
Svein Linge
Hans Petter Langtangen
Publisher
Springer Open
Date
2020
Language
English
License
CC BY 4.0
ISBN
978-3-319-32428-9
Size
17.8 x 25.4 cm
Pages
356
Keywords
Programmiersprache, Informatik, programming language, functional, imperative, object-oriented, reflective
Category
Informatik
Web-Books
Library
Privacy
Imprint
Austria-Forum
Austria-Forum
Web-Books
Programming for Computations – Python