Determining pi experimentally

Assignment Help Business Management
Reference no: EM131861845

Determining Pi Experimentally

Recall that π is the ratio of a circle's circumference to its diameter and that we can calculate the area of a circle with the formula A = π·r2. Below is a circle inscribed within the unit square.

Consider the following questions:

  • What is the ratio of the areas of the inscribed circle to that of the unit square?
  • If we pick a random point within the unit square what is the probability that the point will also lie within the circle?

If we repeat the experiment of choosing points at random an arbitrarily large number of times, the ratio of the number of points which lie within the circle to the number of points within the unit square (all of them) will approach π/4. Using the language structures we have discussed have a program that will do the above experiment an arbitrary (determined at run-time) number of times and report back the approximate value of π.

import java.util.*;

public class DeterminingPi 

{

public static boolean isInside (double x, double y)  

double distance = Math.sqrt((x * x) + (y * y));

return (distance < 1.0);

}

public static double calculatePI (int num) 

{

Random random= new Random (System.currentTimeMillis());  

int repeats = 0;

double PI = 0;

for (int i = 1; i <= num; i++)

{

double x = (random.nextDouble()) * 2 - 1.0;

double y = (random.nextDouble()) * 2 - 1.0;

if (isInside(x, y))

{

repeats++;

}

}

double dRepeats = num;

PI = (4.0 * (repeats/dRepeats));

return PI;

}

public static void main (String[] args)

{

Scanner scan = new Scanner (System.in); 

System.out.print("Please key in the number of times you want to execute the program: ");

int num = scan.nextInt();

double PI = calculatePI(num);

System.out.println ("The value of PI is about " + PI);  

scan.close();

}

}

Reference no: EM131861845

Questions Cloud

Find an app designed to support a business process : Find an app designed to support a business process. What is the business process? How does the app propose to improve it?
What determines the preset value of the counter : Study the data transfer protocol of figure 10-48 and answer the following questions:
Discuss the formats of alternative dispute resolution : Discuss the recognized formats of alternative dispute resolution and its role within the court system.
Explain the cause of digital-crime and non-digital crime : Determine one (1) additional theory that a researcher could use to explain the cause of digital-crime and non-digital crime.
Determining pi experimentally : Recall that p is the ratio of a circle's circumference to its diameter and that we can calculate the area of a circle with the formula A = p·r2.
List key customer wants or needs on left-hand vertical axis : List the key customer wants or needs on the left-hand vertical axis. List competing products on top horizontal axis, starting with your product on the left.
System administrator for the acme corporation : You just started working as a system administrator for the Acme Corporation. Your company decides that as a benefit to its employees, some employees
Conduct an abbreviated literature review related to topic : Conduct an abbreviated literature review related to the topic you selected. A literature review identifies information that is already known about a research.
How to perform a dfs on undirected graph : How to perform a DFS on undirected graph? For example, if a graph contains a lot of vertices and graphs.

Reviews

Write a Review

Business Management Questions & Answers

  Caselet on michael porter’s value chain management

The assignment in management is a two part assignment dealing 1.Theory of function of management. 2. Operations and Controlling.

  Mountain man brewing company

Mountain Man Brewing, a family owned business where Chris Prangel, the son of the president joins. Due to increase in the preference for light beer drinkers, Chris Prangel wants to introduce light beer version in Mountain Man. An analysis into the la..

  Mountain man brewing company

Mountain Man Brewing, a family owned business where Chris Prangel, the son of the president joins. An analysis into the launch of Mountain Man Light over the present Mountain Man Lager.

  Analysis of the case using the doing ethics technique

Analysis of the case using the Doing Ethics Technique (DET). Analysis of the ethical issue(s) from the perspective of an ICT professional, using the ACS Code of  Conduct and properly relating clauses from the ACS Code of Conduct to the ethical issue.

  Affiliations and partnerships

Affiliations and partnerships are frequently used to reach a larger local audience? Which options stand to avail for the Hotel manager and what problems do these pose.

  Innovation-friendly regulations

What influence (if any) can organizations exercise to encourage ‘innovation-friendly' regulations?

  Effect of regional and corporate cultural issues

Present your findings as a group powerpoint with an audio file. In addition individually write up your own conclusions as to the effects of regional cultural issues on the corporate organisational culture of this multinational company as it conducts ..

  Structure of business plan

This assignment shows a structure of business plan. The task is to write a business plane about a Diet Shop.

  Identify the purposes of different types of organisations

Identify the purposes of different types of organisations.

  Entrepreneur case study for analysis

Entrepreneur Case Study for Analysis. Analyze Robin Wolaner's suitability to be an entrepreneur

  Forecasting and business analysis

This problem requires you to apply your cross-sectional analysis skills to a real cross-sectional data set with the goal of answering a specific research question.

  Educational instructional leadership

Prepare a major handout on the key principles of instructional leadership

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd