Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem Setup The Monte Carlo method is commonly used to approximate areas or volumes of shapes. In this problem, we will use Monte Carlo to

Problem Setup

The Monte Carlo method is commonly used to approximate areas or volumes of shapes. In this problem, we will use Monte Carlo to find the area of a circle, allowing us to estimate the value of . Furthermore, we will use several different sample sizes to see how the accuracy increases with larger samples.

Implementation

Part 1

According to the formula A=r2A=r2, for a circle of radius 1, the area of the circle will be equal to . Therefore, if we can use Monte Carlo to approximate the area of the circle, we can find an estimate for .

Write a function calculate_pi that accepts a sample of x and corresponding y coordinates as arguments and returns an estimate for (since we want to calculate for various sample sizes, it will be useful for it to be a function). To simplify things, we will only consider a single quadrant of the unit circle . Therefore, the area of the full circle will be 4 times the area we calculate for the single quadrant (and your function should take this into account).

Part 2

Using the calculate_pi function you wrote in Part 1, estimate the value of for powers of 10 ranging from 100100 to 106106 (inclusive). Store these values in an array named pi. Use the first portion of the coordinates for this purpose. So, if you needed 10 samples, you would do: xs[:10] to get the first 10 samples in xs

Part 3

Plot the absolute error of your approximations vs. the sample size on a log-log plot. The error can be obtained by subtracting the true value of from your approximations.

You should notice that the error decreases with larger sample sizes, although there may be a considerable amount of noise due to randomization. The order of convergence of Monte Carlo is O(1n)O(1n), so the slope of your plot should be around 1/21/2.

In python language

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Programming With Visual Basic .NET

Authors: Carsten Thomsen

2nd Edition

1590590325, 978-1590590324

More Books

Students also viewed these Databases questions