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

One of the first sophisticated uses of the electronic computer was to perform si

ID: 2079288 • Letter: O

Question

One of the first sophisticated uses of the electronic computer was to perform simulations of a complex physical process by using random numbers. The approach is called Monte Carlo and is illustrated using the following simple example. For example, consider a square of side length 1/2 placed inside a bigger square of side 1. It is obvious that the ratio of areas A_2/A_1 = (1/2)^2/1^2 = 1/4 = 0.25 This ratio is equivalent to the probability of a randomly, uniformly selected point from the larger square to also belong to the smaller square. One may write a computer program to estimate such probability. Here, a random point (x, y) is generated whose coordinates are uniformly selected such that 0 lessthanorequalto x lessthanorequalto 1 and 0 lessthanorequalto y lessthanorequalto 1. If the point also belongs to the inner square, we would increment a counter n by 1. The process is repeated many, many times, say m = 1000,000 times. Then the desired probability is estimated as n/m. This is the basis for the Monte Carlo method. Employ the Monte Carlo method and Matlab to estimate the ratio of the gray area to the area of the equilateral triangle of side 2, shown in the following figure. The gray area is defined by the region bounded by the three arcs of radius Squareroot 2 that are centered at the three verities of the triangle, respectively. Also, report the time it takes to execute your Matlab function on our laptop.

Explanation / Answer

m=0; % initializing total no of points in the triangle
n=0; % initializing total no of points in the gray area
dt=0.0001;
for x=0:dt:2 % defining x and y values in the triangle with dt=0.0001
if x<1; p=2*x/sqrt(3);
else if x>=1; p=(2-x)*2/sqrt(3);
end
end
for y=0:dt:p
if sqrt(x^2+y^2)<=sqrt(2) && sqrt((x-2)^2+y^2)<=sqrt(2) && sqrt((x-1)^2+(y-sqrt(3)/2)^2)<=sqrt(2);
% checking whether this point is lies in the gray area or not
% by looking at the distances from the vertices of triangle
% where they should be <=sqrt(2), which is the arc distance
% from the vertices of triangle. here the co-ordinates of
% vertices of triangle are (0,0), (2,0), and (1,sqrt(3)/2).
n=n+1; % add 1 to n if the condition satisfied
end
m=m+1; % add 1 to m for all points to count the total no of points
end
end
prob=n/m; % now the probability becomes the ratio of gray area to the equilateral triangle area

%% the exicution time for this script in my pc is 15 secs for dt=0.0001, and for dt=0.001 or less the time is <1 sec

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