Numerical Integration and Monte Carlo Integration
Numerical Integration and Monte Carlo Integration
f (x)
I= f (x)dx
a
Discretize the x-axis
- n+1 equally spaced points including a,b:
<latexit sha1_base64="GylYjbmqkFiIcBaLkD+c3ZarhnE=">AAAB6HicbVDLSgNBEOyNrxhfUY9eBoPgKexKUI8BQTwmYB6QLGF20puMmZ1dZmaFsAS8e/GgiFc/yZt/4+Rx0MSChqKqm+6uIBFcG9f9dnJr6xubW/ntws7u3v5B8fCoqeNUMWywWMSqHVCNgktsGG4EthOFNAoEtoLRzdRvPaLSPJb3ZpygH9GB5CFn1FipTnvFklt2ZyCrxFuQEixQ6xW/uv2YpRFKwwTVuuO5ifEzqgxnAieFbqoxoWxEB9ixVNIItZ/NDp2QM6v0SRgrW9KQmfp7IqOR1uMosJ0RNUO97E3F/7xOasJrP+MySQ1KNl8UpoKYmEy/Jn2ukBkxtoQyxe2thA2poszYbAo2BG/55VXSvCh7l+VKvVKq3j7N48jDCZzCOXhwBVW4gxo0gAHCM7zCm/PgvDjvzse8NecsIjyGP3A+fwDtf41y</latexit>
h
<latexit sha1_base64="rTY8A/41fKd2STNcY2eiXTDuu2Y=">AAAB6HicbVBNS8NAEJ3Ur1q/qh69LBbBU0mkqMeiF48t2FpoQ9lsJ+3azSbsboQS+gu8eFDEqz/Jm//GbZuDtj4YeLw3w8y8IBFcG9f9dgpr6xubW8Xt0s7u3v5B+fCoreNUMWyxWMSqE1CNgktsGW4EdhKFNAoEPgTj25n/8IRK81jem0mCfkSHkoecUWOl5qhfrrhVdw6ySrycVCBHo1/+6g1ilkYoDRNU667nJsbPqDKcCZyWeqnGhLIxHWLXUkkj1H42P3RKzqwyIGGsbElD5urviYxGWk+iwHZG1Iz0sjcT//O6qQmv/YzLJDUo2WJRmApiYjL7mgy4QmbExBLKFLe3EjaiijJjsynZELzll1dJ+6LqXVZrzVqlfpPHUYQTOIVz8OAK6nAHDWgBA4RneIU359F5cd6dj0VrwclnjuEPnM8f0OeM9Q==</latexit>
h
<latexit sha1_base64="O7Xu1s/0XnX9z4tvwLA2vstsv+M=">AAAB6HicbVDLSgNBEOyNrxhfUY9eBoPgKexKUI8BQTwmYB6QLGF20puMmZ1dZmaFsAS8e/GgiFc/yZt/4+Rx0MSChqKqm+6uIBFcG9f9dnJr6xubW/ntws7u3v5B8fCoqeNUMWywWMSqHVCNgktsGG4EthOFNAoEtoLRzdRvPaLSPJb3ZpygH9GB5CFn1FipPuwVS27ZnYGsEm9BSrBArVf86vZjlkYoDRNU647nJsbPqDKcCZwUuqnGhLIRHWDHUkkj1H42O3RCzqzSJ2GsbElDZurviYxGWo+jwHZG1Az1sjcV//M6qQmv/YzLJDUo2XxRmApiYjL9mvS5QmbE2BLKFLe3EjakijJjsynYELzll1dJ86LsXZYr9Uqpevs0jyMPJ3AK5+DBFVThDmrQAAYIz/AKb86D8+K8Ox/z1pyziPAY/sD5/AH4G415</latexit>
h
<latexit sha1_base64="rTY8A/41fKd2STNcY2eiXTDuu2Y=">AAAB6HicbVBNS8NAEJ3Ur1q/qh69LBbBU0mkqMeiF48t2FpoQ9lsJ+3azSbsboQS+gu8eFDEqz/Jm//GbZuDtj4YeLw3w8y8IBFcG9f9dgpr6xubW8Xt0s7u3v5B+fCoreNUMWyxWMSqE1CNgktsGW4EdhKFNAoEPgTj25n/8IRK81jem0mCfkSHkoecUWOl5qhfrrhVdw6ySrycVCBHo1/+6g1ilkYoDRNU667nJsbPqDKcCZyWeqnGhLIxHWLXUkkj1H42P3RKzqwyIGGsbElD5urviYxGWk+iwHZG1Iz0sjcT//O6qQmv/YzLJDUo2WJRmApiYjL7mgy4QmbExBLKFLe3EjaiijJjsynZELzll1dJ+6LqXVZrzVqlfpPHUYQTOIVz8OAK6nAHDWgBA4RneIU359F5cd6dj0VrwclnjuEPnM8f0OeM9Q==</latexit>
trapezoid
Simpson
For integrands with singularities at the end point(s); open interval formulas
midpoint rule
Alternative:
- interior points have O(h3) errors, sum to O(h2), end points contribute O(h2) errors
Comments on singularities
Open-interval formulas can be used
- singular point(s) should be at end(s); divide up interval in parts if needed
- but convergence with number of points n may be very slow
Divergent part can some times be subtracted and solved analytically
More sophisticated methods exist for dif cult cases
Other methods
Gaussian quadrature:
- non-uniform grid points; n+1 points → exact result for polynomial of order n
- several Julia packages, e.g., FastGaussQuadrature.jl
Gauss-Kronrod quadrature:
- uses two Gaussian quad. evaluations for different n, similarly to Romberg
- package QuadGK.jl uses a version of this method
Adaptive grid (adaptive mesh):
- dynamically adapted to be more dense where most needed
In nite integration range
Change variables to make range nite
fi
fi
Multi-Dimensional integration
fi
Monte Carlo Integration
An integral over a nite volume V:
- is (by de nition) the mean value of the function times the volume
Four repetitions
of a simulation,
dots showing
partial results as
the mean value
evolves