Which solver do I use to determine how many pairs of (X,Y) satisfy the inequality x^2 + y^2 < 1 ?

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);
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

Can you explain what the "ii" and "jj"are? I assumed they were X and Y, but in your last equation sols=[x(ii(idx))' y(jj(idx))'] are y and jj different then?
I tried to type it in to MatLab and got n =
1000
idx =
Empty matrix: 1-by-0
sols =
Empty matrix: 0-by-2
But I don't know how to read that? How many exact pairs satisfy that equation?

Sign in to comment.

Categories

Find more on Random Number Generation in Help Center and File Exchange

Asked:

on 4 Oct 2013

Edited:

Jan
on 6 Oct 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!