MATLAB: MATLAB: I’m having trouble calculating the probability to estimate pi. Any help is appreciated.

The MATLAB command rand produces a uniformly-distributed random number between 0 and 1. For example, the MATLAB commands x = rand; and y = rand; will produce a point randomly located in the unit square: (0<x<1) and (0<y<1). The probability that the randomly-generated point (x, y) will lie within the "unit quarter-circle" is equal to the ratio between the area of the unit quarter-circle and that of a unit square; i.e., ?/4. Note that (x, y) lies within the unit quarter circle if x^2+y^2<1 Write a MATLAB program that will achieve the following tasks. a. Generate a minimum of 10,000 points (x,y). b. Test each point and increment a counter if x^2+y^2<1. c. Produce an estimate of ?. d. Calculate the relative percent true error, E sub t.
n=10000;
for counter=0:n
x= rand;
y=rand;
z=hypot(x,y);
if (z<1)
Est_pi= Area*4;
counter= counter+1;
Error= (((abs(pi-(Est_pi)))/(pi)).*100);
end
end
this is what I have so far.

Best Answer

There is no point in using cumsum() on a scalar like your x.
You never define Area or change it.