R
RadiationX
I have a problem that I really don't understand at all. In my previous
post I could get started on my projects I just had a few problems with
syntax errors. This problem is something that I don't conceptually
understand very well. Here it is:
Π– the ratio of the circumference of a circle to its diameter
– is one of the most common and important constants in mathematics.
It is an irrational number (a real number that cannot be expressed as
the ratio of two integers), but its value has been calculated to more
than a million decimal places using different formulas. (See, for
example, Petr Beckmann's A History of Î , St. Martin's Press: New York,
1971) In this assignment you will estimate the value of Î by
simulating randomly throwing darts at a target.
The figure at the left is a quarter circle of radius 1.0 inscribed in
a square of side 1.0 on the Cartesian plane. It can be show that area
of the dark blue quarter circle is Î /4. If we were to randomly throw d
darts at the square, and c of them landed in the circle, we could
estimate the value of Î /4 as c / d, so an approximation of Î is 4 * (
c / d ).
Your program should "throw" darts at the target by generating a
random coordinate pair (x, y) where x and y are floating point values
in the range [0.0, 1.0], which will represent the point the dart hit
the target. (You can generate numbers in this range with the expression
(double)rand()/RAND_MAX) .) This point will be inside the quarter
circle if:
sqrt( x2 + y2) <= 1.0
By maintaining counters for the number of darts landing in the
quarter circle and the the total number of darts thrown, the value of
Î can be approximated. The larger the number of darts thrown, the
better the approximation will be.
Your program should use a function that, each time it is called,
generates a new random coordinate pair, determines if this pair
represents a point inside the quarter circle, and returns a 1 if it is,
and a 0 if it is not. Your program should run a simulation for a
user-specified number of dart throws, and then display the estimated
value of Î and the percentage difference (percent error) between your
estimated value and the true value of Î ; if your estimated value is p,
then the percent error is (( p - Î ) / Î ) * 100. (The actual value of
Î to 15 significant figures is 3.14159265358979.)
___________________________________________________________________________
I do have some ideas about the variables that I need but I'm not sure
how to really implement the rand()/ RAND_MAX function... could someone
give a start in the right direction?
post I could get started on my projects I just had a few problems with
syntax errors. This problem is something that I don't conceptually
understand very well. Here it is:
Π– the ratio of the circumference of a circle to its diameter
– is one of the most common and important constants in mathematics.
It is an irrational number (a real number that cannot be expressed as
the ratio of two integers), but its value has been calculated to more
than a million decimal places using different formulas. (See, for
example, Petr Beckmann's A History of Î , St. Martin's Press: New York,
1971) In this assignment you will estimate the value of Î by
simulating randomly throwing darts at a target.
The figure at the left is a quarter circle of radius 1.0 inscribed in
a square of side 1.0 on the Cartesian plane. It can be show that area
of the dark blue quarter circle is Î /4. If we were to randomly throw d
darts at the square, and c of them landed in the circle, we could
estimate the value of Î /4 as c / d, so an approximation of Î is 4 * (
c / d ).
Your program should "throw" darts at the target by generating a
random coordinate pair (x, y) where x and y are floating point values
in the range [0.0, 1.0], which will represent the point the dart hit
the target. (You can generate numbers in this range with the expression
(double)rand()/RAND_MAX) .) This point will be inside the quarter
circle if:
sqrt( x2 + y2) <= 1.0
By maintaining counters for the number of darts landing in the
quarter circle and the the total number of darts thrown, the value of
Î can be approximated. The larger the number of darts thrown, the
better the approximation will be.
Your program should use a function that, each time it is called,
generates a new random coordinate pair, determines if this pair
represents a point inside the quarter circle, and returns a 1 if it is,
and a 0 if it is not. Your program should run a simulation for a
user-specified number of dart throws, and then display the estimated
value of Î and the percentage difference (percent error) between your
estimated value and the true value of Î ; if your estimated value is p,
then the percent error is (( p - Î ) / Î ) * 100. (The actual value of
Î to 15 significant figures is 3.14159265358979.)
___________________________________________________________________________
I do have some ideas about the variables that I need but I'm not sure
how to really implement the rand()/ RAND_MAX function... could someone
give a start in the right direction?