Which solver do I use to determine how many pairs of (X,Y) satisfy the inequality x^2 + y^2 < 1 ?
Show older comments
If I have a set of 1000 generated random numbers (X) and another set of 1000 generation random numbers (Y), which solver do I use to determine how many pairs of (X,Y) satisfy the inequality x^2 + y^2 < 1 ?
Answers (2)
x = rand(1, 1000);
y = rand(1, 1000);
s = bsxfun(@plus, x .^ 2, y(:) .^ 2);
n = sum(s(:) < 1);
Azzi Abdelmalek
on 4 Oct 2013
n=numel(x)
[ii,jj]=ndgrid(1:n,1:n);
z=x(ii(:)).^2+y(jj(:)).^2;
idx=find(z<1)
sols=[x(ii(idx))' y(jj(idx))']
1 Comment
Vivienne Tsan
on 5 Oct 2013
Categories
Find more on Random Number Generation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!