6. Monte Carlo integration

Integration is the process of calculating the area inside a region. Typically, this is the area under a curve defined by some function y = F(x). For example, in the following diagram, the goal is to calculate the shaded area under the curve in the domain -2 ≤ x ≤ 1.5:

You can use calculus to integrate the area under a curve, at least if you remember your calculus and the function is reasonably well-behaved. If you cannot apply calculus, then you can use Monte Carlo integration.

From the name and your experience with Monte Carlo approximation for π, you may be able to guess how this works. Pick a rectangle that includes ...

Get Improving your C# Skills now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.