Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using MATLAB In this problem you will be estimating . One way to estimate the ou

ID: 3573696 • Letter: U

Question

Using MATLAB

In this problem you will be estimating . One way to estimate the outcome of for a problem is to use a Monte Carlo simulation which uses a large number of random numbers and then compares the results of these numbers. For estimating , we can visualize a circle of radius 1 inside a square with a side of 2, both centered on zero.

The area of the square is 4 and the area of the circle is . The ratio of the area of the circle to the area of the square is /4. Consequently, if a large number of points (N) with x and y values varying between 1 and -1 is generated, the number of points falling inside the circle would be:

Points in circle = N*/4

The number of points falling inside the circle can be determined by the condition x2 + y2 <= 1. Generate row vectors of uniformly distributed random numbers containing 10000 x-values and 10000 y-values and 1000000 x-values and 1000000-y values. Use the built-in functions of length and find to determine the number of points falling in the circle for the row vectors of 10000 elements and the row vectors containing 1000000 elements. Then use these values to calculate the estimate of . (Do not use any built-in functions other than find, length and rand for this problem.)

The script file should generate row vectors of random numbers You should have 2 scenarios: 10000 x-values and 10000 y-values plus 1000000 x-values and 1000000-y values. Add comments to the end of this problem stating why you did not get the same value for pi for both scenarios.

Explanation / Answer

n(1)=100;
n(2)=1000;
n(3)=10000;
n(4)=100000;
piapprox = zeros(1, 4); % Save approximations
for k=1:4;
count = 0; % count variable, start value set to zero
for i=1:n(k); % for loop initialized at one
x=rand; % rand variable within [0,1] ... points coordinates
y=rand;   

if (x^2+y^2 <=1) %if pair is within the first quadrant of the unit circle
count = count +1; % if yes, it increases the count by one
end
end
piapprox(k) = count;
end

piapprox = 4 .* (piapprox ./ n)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote