An interesting way of calculating a is to use a technique known as Monte Carlo, which...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
An interesting way of calculating a is to use a technique known as Monte Carlo, which involves randomization. This technique works as follows: Suppose you have a circle inscribed within a square, as shown in Figure below (-1, 1)• •(1, 1) • (0, 0) (-1, -1). (1,-1) (Assume that the radius of this circle is 1.) First, generate a series of random points as simple (x, y) coordinates. These points must fall within the Cartesian coordinates that bound the square. Of the total number of random points that are generated, some will occur within the circle. Next, estimate a by performing the following calculation: TT = 4 x (number of points in circle)/(total number of points) Write a multithreaded version of this algorithm in C/C++ that creates a separate thread to generate a number of random points. The thread will count the number of points that occur within the circle and store that result in a global variable. When this thread has exited, the parent thread will calculate and output the estimated value of t. It is worth experimenting with the number of random points generated. As a general rule, the greater the number of points, the closer the approximation to T. A code segment for generating random numbers, as well as determining if the random (x, y) point occurs within the circle is provided below: /* Generates a double precision random number */ double random_double () { return random () / ( (double) RAND MAX + 1); } /* Check for points inside circle for (i = 0; i < npoints; i++) { /* generate random numbers between -1.0 and +1.0 (exclusive) */ x = random double () * 2.0 - 1.03; y = random_double () * 2.0 - 1.0; if (sqrt (x*x + y*y) < 1.0 ) ++hit_count; } Name the program mcarlo.c or mcarlo.cpp and provide the number of points of the command line: > . /mcarlo <number of points> Use at least two worker threads to calculate the total number of points as well and the number of points inside the circle. Error Handling Perform the necessary error checking to ensure the correct number of command-line parameters. Verify the number of points is a valid number and during test vary signficantyl the number of points to see the difference in the accuracy of the estimation of TT. An interesting way of calculating a is to use a technique known as Monte Carlo, which involves randomization. This technique works as follows: Suppose you have a circle inscribed within a square, as shown in Figure below (-1, 1)• •(1, 1) • (0, 0) (-1, -1). (1,-1) (Assume that the radius of this circle is 1.) First, generate a series of random points as simple (x, y) coordinates. These points must fall within the Cartesian coordinates that bound the square. Of the total number of random points that are generated, some will occur within the circle. Next, estimate a by performing the following calculation: TT = 4 x (number of points in circle)/(total number of points) Write a multithreaded version of this algorithm in C/C++ that creates a separate thread to generate a number of random points. The thread will count the number of points that occur within the circle and store that result in a global variable. When this thread has exited, the parent thread will calculate and output the estimated value of t. It is worth experimenting with the number of random points generated. As a general rule, the greater the number of points, the closer the approximation to T. A code segment for generating random numbers, as well as determining if the random (x, y) point occurs within the circle is provided below: /* Generates a double precision random number */ double random_double () { return random () / ( (double) RAND MAX + 1); } /* Check for points inside circle for (i = 0; i < npoints; i++) { /* generate random numbers between -1.0 and +1.0 (exclusive) */ x = random double () * 2.0 - 1.03; y = random_double () * 2.0 - 1.0; if (sqrt (x*x + y*y) < 1.0 ) ++hit_count; } Name the program mcarlo.c or mcarlo.cpp and provide the number of points of the command line: > . /mcarlo <number of points> Use at least two worker threads to calculate the total number of points as well and the number of points inside the circle. Error Handling Perform the necessary error checking to ensure the correct number of command-line parameters. Verify the number of points is a valid number and during test vary signficantyl the number of points to see the difference in the accuracy of the estimation of TT.
Expert Answer:
Answer rating: 100% (QA)
include For random RANDMAX include include define total 1200 int checkvaluei... View the full answer
Related Book For
Data Structures and Algorithms in Java
ISBN: 978-1118771334
6th edition
Authors: Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser
Posted Date:
Students also viewed these finance questions
-
A useful technique for catching typing errors is to use a check digit. For example, suppose that a school assigns a six-digit number to each student. A seventh digit can be determined from the other...
-
Another way to analyze randomized quick-sort is to use a recurrence equation. In this case, we let T(n) denote the expected running time of randomized quicksort, and we observe that, because of the...
-
One-way economists measure total factor productivity is to use a Cobb-Douglas production function of the form q = A (t) KaL1-a, where A (t) is a term representing technical change and a is a positive...
-
Oil flows through the 100-mm-diameter pipe with a velocity of 5 m/s. If the pressure in the pipe at A and B is 80 kpa, determine the x and y components of force the flow exerts on the elbow. The flow...
-
In Section 9.3 we emphasized the notion of "most efficient estimator" by comparing the variance of two unbiased estimators and however this does not take into account bias in case one or both...
-
What are three problems with basing investment decisions on internal rate of return?
-
A wing generates a lift \(\mathscr{L}\) when moving through sea-level air with a velocity \(U\). How fast must the wing move through the air at an altitude of \(10,000 \mathrm{~m}\) with the same...
-
Short answers for sensitivity analysis of Linear Programming: Blue Ridge wanted to produce the Aqua-Spa and Hydro-Lux, but they only had 200 pumps. The company needed to decide how many of each...
-
It uses diagnostic techniques complemented by the use of graphics and visualizations to make it easier to understand, such as flow diagrams for process analysis or bar graphs to show the results of...
-
The proposed rates were not in the range the CEO expected given the pricing analysis. The CEO has asked the pricing actuary to verify the total projected loss cost excluding potential large storm...
-
LAG Network Inc.'s balance sheet and income statement are as follows: LAG Network Inc. Income Statement For Year Ended December 31, 2020 Sales $ 922, 600 550, 200 Cost of goods sold Gross profit $...
-
1. Find the moment of the 500 N force shown about Point A. Write your answer using 2 significant digits. 200 mm B A 30 250 mm F = 500 N
-
1. Describe the similarities and differences between the graphs of two normally distributed sets of data: (ex. which is narrower and why? etc) Data Set A: a data set with a mean of 15 and a standard...
-
Review the NPV results for each project, than answer the questions below, Project 1: Discount Rate (rate of return) 10% Cash flow for year one $0.00 Cash flow for year two $100,000.00 Present value...
-
7. A rectangular box measures 18 in by 24 in by 30 in, as shown. What is the longest stick that can be placed inside the box? Round to the nearest inch. 18 in 24 in 30 in
-
A ) Name some strategies could you use to gain consensus from the team? Describe the strategies and discuss their effectiveness. B) What issue resolution strategies could you use with the team?...
-
Question 2 (20 marks) Ann, Boris, Carrie and Daniel are directors of SpeedRoad Transport Ltd. SpeedRoad is listed in the Australian Security Exchange (ASX) and operates a fleet of 2,000 buses...
-
Solve each equation. x 3 - 6x 2 = -8x
-
Implement a circular version of a doubly linked list, without any sentinels, that supports all the public behaviors of the original as well as two new update methods, rotate( ) and rotateBackward( ).
-
Show how to use a deterministic O(n)-time selection algorithmto sort a sequence of n elements in O(nlogn)-worst-case time.
-
Argue why any solution to the previous problem must run in (n) time.
-
Would a project with 100 tasks always be more challenging to manage than a differ- ent project with only 20 tasks? Why or why not?
-
Is the critical path the shortest or longest path through a project network?
-
A car rental agency uses 96 boxes of staples a year. The boxes cost \($4\) each. It costs \($10\) to order staples, and it costs \($0.80\) to hold a box of staples in inventory for 1 year. Using the...
Study smarter with the SolutionInn App