Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Assignment 1: Assessing the performance of the Monte Carlo

Approximation

The MCA is a powerful tool for solving deterministic problems by feeding random inputs into a
black-box model and sampling outputs to draw conclusions about the model. In practice, such
algorithms always perform better with an increased sample size. Your task is to research the
relationship between the sample size and output of the method we built earlier today by
following the steps outlined below:

1) Run the function from today on an array of varying sample sizes {1, 10, 100, …, 107} via
a for-loop and record the outputs in an array for the function 𝑓(𝑥) = 𝑥 on the closed
interval [0, 3].

Hint 1.1: It is helpful to think of of this array using a power-of-ten representation,


i.e. {100, 101, 102, …, 107}
Hint 1.2: Look up the .append() method of arrays. This is a function unique to Python
that allows you to add values to an empty array.

2) Plot the output of each of the runs with a different sample size versus its respective
sample size on a semilog scale with a grid, title, and labeled axes. Mark each plotted
point with a star (*) for clearer interpretation.

Hint 2.1: Take a look at the example here to review the basics of plotting.
Hint 2.2: The .semilogx() functions much like the .plot() method that we discussed on
Monday, but it changes to x-axis to a logarithmic scale. This makes every successive cell
increase by an order of magnitude, rather than by a fixed amount.

Your graph should look like this:

You might also like