
Natalie N.
asked 02/23/251. Some functions are too complicated to integrate exactly, even when using sympy or other computer algebra systems. However, there are ways to approximate the definite integrals of such functions.
In this problem, we will be using a Monte Carlo algorithm (named after a famous casino because this algorithm uses random numbers to approximate an answer) to approximate the area under a curve.
(a) Let f(x) = x^3/ e^x−1 and plot it on the x-interval [0, 5]
(b) The algorithm randomly chooses points in a rectangle containing the region whose area we wish to compute. For any one of these points, its probability of being under the curve is ∫ 0 to 5 f(x)dx /rectangle area since we assume every point in the rectangle is equally likely to be chosen. We will then generate a bunch of random points and count how many were under the curve.
We then solve for the approximate value of the integral once the other values have been estimated. For this problem, we will use the rectangle [0, 5] × [0, 1.5]. Create a loop that repeats the following process:
• Randomly generate a point (x, y) belonging to the rectangle. Do this one coordinate at a time using the random.uniform(a,b) command, where a and b are your lower and upper bounds.
• Check whether the point is under the curve.
• If it is, then increase your current count of points under the curve by 1. Use your loop and the proportion relation above to approximate ∫ zero to 5f(x)dx by generating 1000 points
(c) Reuse your loop to approximate ∫zero to 5 f(x)dx by generating 5000 points instead.
1 Expert Answer

Angel M. answered 02/24/25
Experienced Data Analyst Specialized in Python
a) You can use Numpy and matplotlib to create a Python function that represent the f(x) and plot it that way.
b) With the dimension given you can find the area of the rectangle and then use a for loop to generate random points based on those limits and you can check if the random points are under the curve inside of the for loop.
c) Reuse the same code from part b, only this time you are generating 5000 random points.

Doug C.
And here is a Desmos graph that does the same: desmos.com/calculator/lokpjkq5to03/20/25
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Mark M.
Did you plot f(x)? Did you generate random numbers and plot? Did you ever consider starting these on your own?02/23/25