O'Reilly logo

A Concise Introduction to Programming in Python by Mark J. Johnson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 10

Simulation

Consider the problem of finding the area under the curve f(x)= e x 2 between x = 0 and x = 2:

Figure 10.1:

Figure showing graph of f(x)= e−x2.

Graph of f(x)= e x 2 .

Even if you know calculus, this is a difficult task. However, a relatively simple idea will allow us to approximate the area.

The idea begins with putting a box around the graph that contains it completely. For a function that stays positive, this means finding a maximum value m; in this case, we can use m = 1:

Figure 10.2:

Figure showing box containing area.

Box containing area.

Now imagine throwing random ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required