Question

Can't seem to figure this out as a matlab file and was looking for help, you...

Can't seem to figure this out as a matlab file and was looking for help, you can't use any for or while loops and all functions used must be built into matlab.

Consider a square dartboard with each side having dimension equal to 2.

Centered inside this square place a circle having radius 1.

Now throw N = 1e4 darts at the dartboard in a random fashion so that they

are uniformly distributed over the surface of the dartboard.

The area of the circle is pi*radius^2. Given a radius of 1, the area of

the circle is equal to pi.

The area of the square is 2 * 2 = 4

The ratio of the circle area to the square area is pi/4. If this value is

multiplied by 4, the result is pi.

Since the darts are uniformly distributed over the dartboard, the ratio

of the darts that are in the circle to the total number must approximate

pi/4. So, multiplying this ratio by 4 will give an approximation to pi.

No For or While loops permitted.

No extraneous output to the Command Window.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Let us assume that the center of the board is at the origin. Every time a dart is thrown it will be at a location given by its x-coordinate and y-coordinate. So, we generate 1e4 such coordinates and then count the number that falls into the circle of radius 1.

The MATLAB code for generating the random coordinates (uniformly distributed) and counting the number of darts in the circle of radius 1, is given below:

x=-1+2*rand(1,1e4); % generate 1e4 random x-coordinates between [-1,1]
y=-1+2*rand(1,1e4); % generate 1e4 random y-coordinates between [-1,1]

z=x.*x+y.*y; % to check whether the coordinates are inside the unit circle
count=length(find(z<=1));

ratio=count/length(x);

pi_value=ratio*4;

=========================================================================

Running the above code in MATLAB yields count as 7862 and the value of \pi as 3.1448

==========================================================================

I really enjoyed answering this question. Hope that I have answered your question. Share your thoughts through your comments.

Add a comment
Know the answer?
Add Answer to:
Can't seem to figure this out as a matlab file and was looking for help, you...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This problem deals with continuous (rather than discrete) probability, but it's an interesting problem! It involves...

    This problem deals with continuous (rather than discrete) probability, but it's an interesting problem! It involves probabilistically estimating the value of pi. Consider a circle of radius 1 inscribed within a square with side 2. Both shapes are centered at the origin (0, 0). Using basic geometry, the ratio of the circle's area to the square's area is pi (1)^2/2^2 = pi/4. Now, suppose that you randomly throw some darts at this figure. Out of n total attempts, m attempts...

  • C++ Pr ogramming (CSC-115) Functions (pass by Reference) Programming project Using FUNCTIONS, write a C++ program...

    C++ Pr ogramming (CSC-115) Functions (pass by Reference) Programming project Using FUNCTIONS, write a C++ program that calculates the Area of a cirele, a square and a rectangle. Your program must prompt the user to select which area is to be calculated. Document your program. Apply the do while loop to repeat the program Apply the while loop for input validation. Apply the switch statements or the if/ else if statement to prompt the user for the area's selection. Based...

  • No loops can be used and must only use functions that are built into matlab, aka...

    No loops can be used and must only use functions that are built into matlab, aka no toolboxes FACTORS All Factors of an Integer FACTORS(N) returns all the factors of the positive integer N. For example: FACTORS(60) returns the 2 X 6 array [ 1 2 3 4 5 6 60 30 20 15 12 10] FACTORS(25) returns the 2 X 2 array [ 1 5 25 5] FACTORS(7) returns the 2 X 1 array [1 7] If N is...

  • Write a PYTHON program that will approximate the value of π. You can do this by...

    Write a PYTHON program that will approximate the value of π. You can do this by computing π to be the ratio of the area of a circle to the area of the square that bounds that circle. Assume a circle of radius 0.5 enclosed by a 1x1 square. The area of the circle then is πr^2=π/4, since r=0.5=1/2 and the area of the square is 1. To approximate the ratio, take a large number of uniformly distributed random points....

  • need help with matLab Question 1 (20 Points) Write a well-documented MATLAB script hmwk7Q1.m that simulates...

    need help with matLab Question 1 (20 Points) Write a well-documented MATLAB script hmwk7Q1.m that simulates tossing 100 coins into a unit square. As shown in the scatter plot. Location of Simulated Coins In Unit Square 1 o0 Ooo 05 04 03 02 oo 0.1 2 03 4 05 07 1 xpostion Hmwk7Q1.fig Consider organizing your MATLAB script into the following sections. % housekeeping (performs clearing of figures, workspace, and command lines) % Initialize the Number of Coins To Simulate...

  • BME 2013 Spring 2019 Exam 3 Matlab Review Sheet 1. Given the vector of patient body temperatures ...

    can anyone help me figure out how fo write matlab code for these problems? BME 2013 Spring 2019 Exam 3 Matlab Review Sheet 1. Given the vector of patient body temperatures T (98.6, 102, 101, 99,98.9, 102.1, 100.3, 101.2, 98.4 97.6, 100] use conditional statements and loops to write a program that determines and displays (using the fprintf function) the number of patients with a fever and patients without a fever. The program must ask the user to input the...

  • Create a NOTEPAD or PDF file that restates the problem in your own words, specifies what input is needed, w...

    Create a NOTEPAD or PDF file that restates the problem in your own words, specifies what input is needed, what output is expected, the step by step process (algorithm) to get the output from the input, and test data (input for which you know the expected output) for each of the 3 problems given below. You should not write any actual C++ code. Make sure the problem statement is in your own words and is descriptive enough so someone not...

  • Nay programming languge is fine (MatLab, Octave, etc.) This is the whole document this last picture...

    Nay programming languge is fine (MatLab, Octave, etc.) This is the whole document this last picture i sent is the first page 5. Write and save a function Sphere Area that accepts Radius as input argument, and returns SurfaceArea (4 tt r) as output argument. Paste the function code below. Paste code here 6. Validate your Sphere Area function from the command line, checking the results against hand calculations. Paste the command line code and results below. 7. Design an...

  • I can't figure out the formula for each one? Home Insert Draw Page Layout Formulas Data...

    I can't figure out the formula for each one? Home Insert Draw Page Layout Formulas Data Review View 2 E E N DO E Get Add-ins G?- c rv - the slicer e Timeline Link New Comm Plvot Table Recommended Table Pictures Shapes Icons My Add-ins v Recommended 0 vN Maps PivotChart Sparklines Pivot Tables Charts 015 , X fx ACDEFGHIJKLMNOP T U Problem 1: Bernoulli's equation relates the pressure and velocity of a fluid. It states: p+50V2 + pgh...

  • Project 1 – Classes and Top-down Design Overview Software development projects using the object-oriented approach involve...

    Project 1 – Classes and Top-down Design Overview Software development projects using the object-oriented approach involve breaking the problem down into multiple classes that can be tied together into a single solution. In this project, you are given the task of writing some classes that would work together for providing a solution to a problem involving some basic computations. Learning Objectives The focus of this assignment is on the following learning objectives: • Be able to identify the contents of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT