Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is for a Java class and needs to be in java language, Math 130. And we have not covered arrays yet. Just if, if

This is for a Java class and needs to be in java language, Math 130. And we have not covered arrays yet. Just if, if then, for, nested, print if, if-else loops. I would very much appreciate having explanations on how and why certain methods are used, so that I can learn. Thank you :)

image text in transcribed

Assignment 4: The Monte Carlo Method for simulation Submit Assi Due Mar 14 by 11:59pm Points 10 Submitting a text entry box or a file upload File Types Available Mar 5 at 12am - Mar 14 at 11:59pm 10 days Monte Carlo methods (or Monte Carlo experiments) are a broad class of computational algorithms that rely on repeated random sampling to obtain numerical results. Their essential idea is using randomness to solve problems that might be deterministic in principle Consider the following experiment: By shooting darts to a square wooden board with an inscribed circle, the probability of landing a shoot inside the circle is proportional to the ratio of both areas. If we use a board like the one below: The area of the square is 4 and the area of the circle is Therefore, the probability of landing a dart inside the circle is0.78539816 Write a program that shoots darts at random. That is, generate a pair of random numbers x and y Using a Cartesian plane, with the center of the circle in the origin, the square will cover the area from -1 to 1 in both horizontal and vertical directions Each dart will be considered landing in (x.y) where x and y are random numbers between -1.0 and 1.0. A dart will be considered inside the circle if and only if the distance from (xy] s less than the radius of the circle, which is 1.0 The formula for distance between 2 points is . distance - -)) If one of the points is (0,0), the formula simplifies more. Define a method that calculates the distance of any given point (a,b) to the origin. " Using a loop, shoot 100 darts, measure the distance from (0 with your method. If the distance is less than one, your dart is inside the circle and you get one point Award yourself one point for each dart landing inside the circle A dart landing outside gives you zero points Finally,after shooting 100 darts, the probability is the number of points divided by the totall number of darts. Don't forget to typecast those integers to double. The quotient is the ratio of both areas, and represents the probability of a dart landing inside the circle. Te value should be close to Report your results by printing the quotient multiplied times 4.0. That number should look like Repeat the process using 1000, 10000, 100000, 1000000 and 10000000 darts. . Compare your results for different amount of darts. It is expected that when more darts are shoot the probability will approach closer and closer to This is a classic example of a Monte Carlo experiment, where theoretical probabilities can be approximated by experimental results Your program is a Monte Carlo simulator Submit your code and a sample run using the different numbers of darts. You can use a nested loop to get all done in one single run

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions