1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
AlexFokin [52]
3 years ago
12

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

ind 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. PYTHON
Part 1

According to the formula A=Ïr^2, 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 (see gif above). 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 different sample size of powers of 10 ranging from 10^0 to 10^6 (inclusive). Store these values in an array of size 7 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(1ân), so the slope of your plot should be around â1/2.

Output

The setup code gives the following variables:

Name Type Description
xs 1-d numpy array random numbers from 0 to 1
ys 1-d numpy array random numbers from 0 to 1
Your code snippet should define the following function(s) and variable(s):

Name Type Description
calculate_pi function function accepting 2 arrays (x and y sample coordinates, respectively) and returning an estimate for ÏÏ
pi 1-d numpy array estimates for ÏÏ as described above
We also ask for a plot of error vs. sample size. (Provide appropriate axes labels and a title.)
Computers and Technology
1 answer:
sdas [7]3 years ago
4 0

Answer:

import numpy as np

import matplotlib.pyplot as plt

def calculate_pi(x,y):

   points_in_circle=0

   for i in range(len(x)):

       if np.sqrt(x[i]**2+y[i]**2)<=1:

           points_in_circle+=1

       pi_value=4*points_in_circle/len(x)

       return pi_value

length=np.power(10,6)

x=np.random.rand(length)

y=np.random.rand(length)

pi=np.zeros(7)

sample_size=np.zeros(7)

for i in range(len(pi)):

   xs=x[:np.power(10,i)]

   ys=y[:np.power(10,i)]

   sample_size[i]=len(xs)

   pi_value=calculate_pi(xs,ys)

   pi[i]=pi_value

 

print("The value of pi at different sample size is")

print(pi)

plt.plot(sample_size,np.abs(pi-np.pi))

plt.xscale('log')

plt.yscale('log')

plt.xlabel('sample size')

plt.ylabel('absolute error')

plt.title('Error Vs Sample Size')

plt.show()

Explanation:

The python program gets the sample size of circles and the areas and returns a plot of one against the other as a line plot. The numpy package is used to mathematically create the circle samples as a series of random numbers while matplotlib's pyplot is used to plot for the visual statistics of the features of the samples.

You might be interested in
Write a function that receives two numbers, m and n and calculates and displays the sum of the integers from m to n. For example
Evgesh-ka [11]

Answer:

The program to this question as follows:

Program:

//header file

#include <stdio.h> //defining header file

void inc(int m,int n) //defining method inc

{

   int sum, i; //declaring variable

   sum=m; //holding value of m variable

   for(i=++m;i<=n;i++) //loop for calculate number between given range  

   {

   sum=sum+i; //adding value

   }

   printf("sum of the integer is : %d",sum);//print value

}

int main() //defining method

{

   int m,n; //defining integer variable

   printf("Enter m value: "); //message

   scanf("%d",&m); //input value by user in variable

   printf("Enter n value: "); //message

   scanf("%d",&n);//input value by user in variable

   inc(m,n); //calling method

   return 0;

}

Output:

Enter m value: 3

Enter n value: 7

sum of the integer is :25

Explanation:

In the above code, an "inc" function is declared, that accepts integer parameters that are "m and n", inside the method two integer variable "sum and i" is declared, which is used in the loop.

  • The loop uses the user parameter to count value and uses the sum variable to calculate there sum.
  • In the main method, two integer variable n and m are declared, which take value from the user end, and at the last, we call the inc method, that prints sum value.
7 0
2 years ago
What sorts of routine, seemingly unimportant information would help you learn about or break into another company’s network?
tatuchka [14]

Answer and Explanation:

  • Reboot your Computer from which you need to break into.
  • With your remote Ethernet card embedded and the unprotected passageway will mate up in a flash. You likewise need to change the Service Set Identifier (SSID) on your Ethernet card to coordinate SSID on the system's passage. You can decide to physically constrain your DHCP settings to reestablish, however on the off chance that that gives you any trouble.we need to re-boot it.
  • The Third Man ran a sniffer program that caught the majority of the LAN traffic within this organization. It was transmitted through the remote passageway straight into the Third Man's PC. Passwords. Agreements. Email.
4 0
3 years ago
Movie Hidden Figures
Setler79 [48]

Answer:

D: 97

Explanation:

i watched this movie 3 times

4 0
2 years ago
Explain Organizational approach to System Analysis and Design
9966 [12]

Answer:

The major goal of systems analysis and design is to improve organizational systems. Often this process involves developing or acquiring application software and training employees to use it. Application software, also called a system, is designed to support a specific organizational function or process, such as inventory management, payroll, or market analysis. The goal of application software is to turn data into information. For example, software developed for the inventory department at a bookstore may keep track of the number of books in stock of the latest best seller. Software for the payroll department may keep track of the changing pay rates of employees. A variety of off-the-shelf application software can be purchased, including WordPerfect, Excel, and PowerPoint. However, off-the-shelf software may not fit the needs of a particular organization, and so the organization must develop its own product.

Explanation:

Information systems analysis and design is a method used by companies ranging from IBM to PepsiCo to Sony to create and maintain information systems that perform basic business functions such as keeping track of customer names and addresses, processing orders, and paying employees. The main goal of systems analysis and design is to improve organizational systems, typically through applying software that can help employees accomplish key business tasks more easily and efficiently. As a systems analyst, you will be at the center of developing this software. The analysis and design of information systems are based on:

Your understanding of the organization’s objectives, structure, and processes

Your knowledge of how to exploit information technology for advantage

7 0
3 years ago
Microsoft excel is a ____application.
gavmur [86]
<span>Microsoft Excel is a spreadsheet developed by Microsoft for Windows, Mac OS X, Android and iOS.</span>
4 0
3 years ago
Other questions:
  • F we are reduced to a set of computer algorithms, how do we differentiate ourselves from our programming or our connectome? is i
    8·1 answer
  • Which of the following is most likely to be considered plagiarism? Using materials from a source without proper citation. Adding
    5·1 answer
  • Check my work a(n) ________ reference is an automatically created variable that holds the address of an object and passes it to
    15·1 answer
  • Abusive behavior, which involves the use of an electronic communications device, that is degrading, humiliating, hurtful, insult
    14·1 answer
  • You are requesting information about wireless connectivity for your workplace computers. Because you expect the information to b
    15·1 answer
  • Are to print or find<br> the sum<br> 5 numbers<br> of<br> using flow chart
    6·1 answer
  • 6
    5·1 answer
  • You manage a network that uses switches. In the lobby of your building, there are three RJ45 ports connected to a switch. You wa
    5·1 answer
  • Part 2: Code the Program
    12·1 answer
  • What is a best practice when approaching an automation effort?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!