MatLab Question 2. Approximate the value of by considering a quarter unit circle
ID: 3589156 • Letter: M
Question
MatLab Question
2. Approximate the value of by considering a quarter unit circle enclose inside a square. The shaded quarter circle area is r2/4 = . 13(4 = /4. The area of the circle can be approximated by choosing a large number of random points inside the square and counting the percentage that fall inside the quarter circle. The equation of a circle with unit radius centered at the origin is This is rearranged to give so any (x.y) point inside the square is also is inside the black area if The area inside the square is one square unit and so the ratio of points inside the black area represents the area of the black area. Inside a loop, choose a random position inside the square. Increment a counter if the point falls inside the quarter circle. Dividing the counter by the total points used gives the ratio of the black area to 1 square unit of area. Knowing computed black area to equal /4 allows solving for Execute the loop a sufficient number of times to obtain an accurate approximate of pi to 3 significant figures.Explanation / Answer
here is the matlab function to print the circle with the given circle equation:-
function h=circle (x,y,r)
hold on
th=0:pi/50:2*pi;
xunit=r*cos(th)+x;
yunit=r*sin(th)+y;
h=plot(xunit,ynuit);
hold off
if you want to print the segment of the circle :-
function h=circle(x,y,r,segments)
if nargin <4
nsegments=50;