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

  National health planning resource and development act

Select among any health care policies such as Hill-Burton, Medicare/caid, National Health Planning Resource and Development Act.

  Does the organizational culture inspire behaviors

Does the organizational culture inspire behaviors that support the strategy? Are mission, vision, and values clearly articulated and aligned with the strategy?

  Explain how the phone and pomegrants phone prices

Explain how the phone and pomegrants phone prices and quantity demanded will change if a new type of wakie-talkie has an unlimited range and is basically free

  Discuss the rights and responsibilities of healthcare

Discuss the rights and responsibilities of healthcare providers and medical practices in regards to professional liability insurance.

  How do you feel about people conducting eye tracking studies

Good start everyone. So, let's throw some topics from this week together. How do you feel about people conducting eye tracking studies without the consumer's knowledge?

  Probable defense for the baseball gear job

Review the "Case Application 3-B: TEAM FUN!   This is a team assignment, I just have to answer question #4 with 250 words. Please include references.  The scenario is below. Prepare a 1,050- to 1,400-word paper answering the following:

  Purpose of airport marketing initiative

After you have viewed the video discuss the purpose of this airport's marketing initiative, and its effect on the intended target segments.

  Internal and external selection methods

Examine a minimum of three internal and external selection methods you could use to evaluate potential candidates for the strategic staffing

  Distinguish task conflict from relationship conflict

Distinguish task conflict from relationship conflict and explain how to apply the former, with minimal levels of the latter. Explain/Support fully.

  Role of information security policy

Information security policies are the core internal guidance for an organization and must be enacted prior to the purchase of information security controls.

  Differentiate reinforcing and balancing

Differentiate "reinforcing" and "balancing" feedback loops. Explain the concept of "manager as designer" of organizational structures.

  Review each of the six articles you found and summarize them

Review each of the six articles you found and summarize them based on the following criteria: The name of the author and article.

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