Need help with your Discussion

Get a timely done, PLAGIARISM-FREE paper
from our highly-qualified writers!

glass
pen
clip
papers
heaphones

Method from That Class Python Question

Method from That Class Python Question

Method from That Class Python Question

Description

  1. and use a for loop to create 5 random points. (Note: you’ll need to import the random module to get numbers between 0 and 1, which you can send as arguments for x and y in the Point constructor.)
  2. Use the method from that class to to calculate the distance of each point from the origin for all 5 points.
  3. Print out the 5 points.

Your output will look something like this:

Sample 0 is: ( 0.11471474769443413 , 0.3491816944590306 )
Distance from origin: 0.36754228203551964
Sample 1 is: ( 0.7961816110068073 , 0.2519538252406587 )
Distance from origin: 0.8350963344182487
Sample 2 is: ( 0.4792875820033966 , 0.48809981627822585 )
Distance from origin: 0.684074569702383
Sample 3 is: ( 0.5255371295631991 , 0.378753604810677 )
Distance from origin: 0.6477990179883025
Sample 4 is: ( 0.7965471984894288 , 0.2921313660556841 )
Distance from origin: 0.8484268822090195

The idea is to imagine a square inside of which is inscribed a circle with a radius of 1. Any point inside the square may or may not also be inside the circle because while the circle is completely contained within the square, the corners of the square are outside the circle. We know that the area of a circle is A = πr2, so the ratio of points that fall within the circle and not the square should be 3.14159.. to 4 (consider, the area of this square is 2×2 = 4). So give 4000 points, we would expect about 31415 of them to be within the circle, and the rest to be in the corners. If we took a million points, how many should be within the square? That’s the key idea that will allow you to code this solution.

Import the math module into your program. You can get a very close approximation of pi by printing math.pi — that’s data, not a method, so no parenthesis.

Now you will want to estimate pi yourself by creating a million random points, and seeing how many fall within the circle. How do you know if a random point is in the circle or outside of it? Recall that the circle we are modeling has a radius of 1. If the random point is more than 1 unit away from the origin in our model, it’s outside.

use one million points in your simulation and:

  1. Calculate and print out how many of the points in the simulation fall within the circle modeled by your program
  2. Print out the actual value of pi according to Python’s math module
  3. Calculate and print out the estimated value of pi according to your Monte Carlo simulation
  4. Calculate and print out the difference between the actual and simulated value pi

Your finished output may look something like this:

Sample 0 is: ( 0.35068785782177514 , 0.11324034323689292 )
Distance from origin: 0.36851777292287397
Sample 1 is: ( 0.5389232611881516 , 0.40900797588824733 )
Distance from origin: 0.6765543627749907
Sample 2 is: ( 0.38472628641220064 , 0.12478783764413526 )
Distance from origin: 0.404458057010145
Sample 3 is: ( 0.6433022507367676 , 0.7044265510623535 )
Distance from origin: 0.9539677938193687
Sample 4 is: ( 0.08902634180720548 , 0.280591375471971 )
Distance from origin: 0.2943759662826196


785855 of the 1000000 are inside.
actual pi is about 3.141592653589793
estimated pi is about 3.14342
monte carlo simulation is off by -0.001827346410206765

Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."

Order Solution Now

Our Service Charter


1. Professional & Expert Writers: Eminence Papers only hires the best. Our writers are specially selected and recruited, after which they undergo further training to perfect their skills for specialization purposes. Moreover, our writers are holders of masters and Ph.D. degrees. They have impressive academic records, besides being native English speakers.

2. Top Quality Papers: Our customers are always guaranteed of papers that exceed their expectations. All our writers have +5 years of experience. This implies that all papers are written by individuals who are experts in their fields. In addition, the quality team reviews all the papers before sending them to the customers.

3. Plagiarism-Free Papers: All papers provided by Eminence Papers are written from scratch. Appropriate referencing and citation of key information are followed. Plagiarism checkers are used by the Quality assurance team and our editors just to double-check that there are no instances of plagiarism.

4. Timely Delivery: Time wasted is equivalent to a failed dedication and commitment. Eminence Papers are known for the timely delivery of any pending customer orders. Customers are well informed of the progress of their papers to ensure they keep track of what the writer is providing before the final draft is sent for grading.

5. Affordable Prices: Our prices are fairly structured to fit in all groups. Any customer willing to place their assignments with us can do so at very affordable prices. In addition, our customers enjoy regular discounts and bonuses.

6. 24/7 Customer Support: At Eminence Papers, we have put in place a team of experts who answer all customer inquiries promptly. The best part is the ever-availability of the team. Customers can make inquiries anytime.

We Can Write It for You! Enjoy 20% OFF on This Order. Use Code SAVE20

Stuck with your Assignment?

Enjoy 20% OFF Today
Use code SAVE20