Let me make my complaint more explicit by means of concrete example.
Let's consider part (a), but instead of
, we instead use
.
Here's the implementation:
import sys
import random
def sampleS():
x = random.random()
y = random.random()
return (x,y)
def sampleA():
x=random.random()
if (x>=0.5):
y=random.uniform(0,x)
if (x<0.5):
y=random.uniform(x,1)
return (x,y)
def inT(x,y):
if (x>=0.5):
s,a,b,c=0.5,y,x-y,1-x
if (x<0.5):
s,a,b,c=0.5,x,y-x,1-y
return max(a,b,c)<s
def f(x,y):
if (x>=0.5):
s,a,b,c=0.5,y,x-y,1-x
if (x<0.5):
s,a,b,c=0.5,x,y-x,1-y
# return (s*(s-a)*(s-b)*(s-c))**0.5
return (x-0.5)**2
def avg(data):
return sum(data)/float(len(data))
# Experiment 1
data1 = [f(*p) for p in [sampleS() for _ in xrange(10**5)] if inT(*p)]
print avg(data1)
# Experiment 2
data2 = [f(*p) for p in [sampleA() for _ in xrange(10**5)] if inT(*p)]
print avg(data2)
Sure enough, the results are different:
in first case and
in second case.
But if I replace
with area triangle, or even
, then the results seem to match up. So there must be something about the function
itself that is involved in part (a).
This post has been edited 1 time. Last edited by v_Enhance, May 26, 2017, 2:51 PM