Message Boards Message Boards

0
|
1951 Views
|
1 Reply
|
2 Total Likes
View groups...
Share
Share this post:
GROUPS:

Darts in the Heart or Cardioid's Area

Posted 10 years ago

A Cardioid in polar coordinates by the equation r = a(1 - cos[Theta] ): and in the Cartesian coordinates by c(x; y) = a^2(x^2 + y^2)- (x^2 + y^2 + ax)2^ = 0:

  1. Use RandomReal to create a table samp of 1000 random point (x; y) inside the square Q defi ned by the inequalities x=[-1,1] and y=[-1,1].
  2. Create another list samp1 consisting of True and False showing whether each one of the random points hit inside or outside. It can be verified by testing whether c(x; y) > 0 holds or not using the function TrueQ.
  3. Use the function Count to fi nd the proportion p of the points that hit inside.

My solution for Q1 is

List[(1/3)^2 (x^2 + y^2) - (x^2 + y^2 + x/3)^2 /. {x -> 
    RandomReal[{-1, 1}, 1000], y -> RandomReal[{-1, 1}, 1000]}]

My solutionfor Q2 is

f = TrueQ[{(1/3)^2 (x^2 + y^2) - (x^2 + y^2 + x/3)^2} > 0]
Apply[f, %5, {1}]

{False[-0.364859], False[-0.137171], False[-1.11537], False[-1.43534],
  False[-0.0841048], False[0.00326205], False[-0.140792], 
 False[0.00237835], False[-0.0497538], False[-0.637881], 
 False[-0.0625669], False[0.00526883], False[-0.00174536], 
 False[-1.02006], False[0.00438211], False[-0.0138601], 
 False[-0.71684], False[-0.579461], False[-0.106792], False[-1.97075],
  False[0.00416175], False[-0.709583], False[0.0113121], 
 False[-0.0134942], False[-0.111677], False[-0.00493771], 
 False[0.000536444], False[-1.68395], False[-3.57889], 
 False[-0.266902], False[-1.64405], False[0.0108151], 
 False[-0.120763], False[-0.27064], False[-0.309429], False[-2.14915],
  False[-0.26584], False[-0.738133], False[-0.68812], False[-1.85462],
  False[-0.138208], False[-0.149826], False[-0.374574], 
 False[-0.00887895], False[-0.0832324], False[-1.23744], 
 False[-0.437844], False[-0.0872415], False[-0.508862], 
 False[-0.63487], False[-0.343906], False[-1.29864], False[-0.501573],
  False[-1.45845], False[-0.0640027], False[-0.500313], 
 False[-0.294349], False[-0.0788986], False[-0.0821013], 
 False[-0.035108], False[-0.610706], False[-0.383578], 
 False[-1.97819], False[-0.444473], False[-0.0871164], 
 False[-0.236992], False[-0.508493], False[-0.000468644], 
 False[-0.381657], False[-0.0932811], False[-3.07075], 
 False[-3.78931], False[-0.0956325], False[-0.219677], 
 False[-0.267446], False[-1.19195], False[-0.0039328], 
 False[-0.971628], False[-0.308009], False[0.00190915], 
 False[-3.66941], False[-0.0937789], False[-0.0733696], 
 False[-0.180612], False[0.00509671], False[-0.00792352], 
 False[-0.132187], False[-0.27107], False[-0.715274], 
 False[-0.691067], False[-1.13616], False[-0.157806], 
 False[0.0129047], False[-0.740915], False[-2.27933], False[-2.44669],
  False[-0.00106095], False[-0.524533], False[-0.163428], 
 False[-1.60779], False[-0.0207064], False[-1.74797], 
 False[-0.0810224], False[0.00706883], False[-0.146192], 
 False[-0.46698], False[0.00297469], False[-0.158956], 
 False[-0.0913044], False[-0.668241], False[0.00139566], 
 False[0.0147539], False[-0.102365], False[0.00223452], 
 False[-0.00228835], False[-1.06531], False[-1.29459], 
 False[0.0140777], False[-0.0737104], False[-0.273723], 
 False[-0.605346], False[-0.54982], False[-0.254807], False[-0.80592],
  False[-0.065964], False[-0.895564], False[-0.248649], 
 False[0.00255728], False[-0.00115931], False[-0.691998], 
 False[-0.0926432], False[-0.190026], False[-0.220661], 
 False[-1.87094], False[-0.541494], False[-0.404859], 
 False[-0.962051], False[0.00272715], False[-1.07053], 
 False[-1.55732], False[-1.16238], False[-0.0750492], False[-1.86285],
  False[-0.229419], False[-0.532531], False[-1.30887], 
 False[-0.553022], False[-0.00113398], False[-4.32257], 
 False[-0.333929], False[-0.208333], False[0.00278552], 
 False[-0.469594], False[-2.44147], False[0.0195567], False[-2.45742],
  False[0.0142269], False[0.00968775], False[-0.0479316], 
 False[0.00400051], False[-0.0484103], False[-0.782547], 
 False[-0.782309], False[-0.00284635], False[-0.238501], 
 False[-2.86897], False[-0.929457], False[-0.886625], 
 False[0.00966545], False[0.010078], False[-0.0406939], 
 False[-0.134009], False[0.00798344], False[-0.367338], 
 False[-0.752466], False[-0.351509], False[-0.268382], 
 False[-2.02264], False[-0.97872], False[-0.688078], False[-1.11188], 
 False[-0.560345], False[-0.254168], False[-0.128684], 
 False[-0.421768], False[-2.44354], False[-0.377818], 
 False[-0.0550284], False[-1.58268], False[-0.255856], 
 False[-0.000973918], False[-1.14092], False[0.00193466], 
 False[-0.129782], False[-1.55703], False[-0.51643], False[-0.037853],
  False[-0.327266], False[-0.0379186], False[-0.515986], 
 False[-0.285907], False[-0.0449053], False[-1.62629], 
 False[-0.0153312], False[-1.17306], False[-0.293706], 
 False[-0.736712], False[0.0208212], False[-0.983102], 
 False[-1.02395], False[-0.776049], False[0.00448807], 
 False[-0.0230338], False[-0.0269501], False[-0.516977], 
 False[-0.364196], False[-0.617152], False[-0.415148], 
 False[-0.395026], False[-0.102838], False[-0.155421], 
 False[-1.21245], False[-0.00390681], False[-0.851553], 
 False[-0.0314251], False[-0.499504], False[-0.201265], 
 False[-0.198265], False[-0.0373184], False[-0.00869795], 
 False[-0.53856], False[-1.3145], False[-0.616525], False[-1.58246], 
 False[-0.00205891], False[0.00160711], False[-0.303766], 
 False[-0.543213], False[-0.412602], False[-0.0151992], 
 False[-1.01659], False[-0.589628], False[-0.140644], False[-2.16928],
  False[0.0134523], False[0.0201572], False[-0.0146793], 
 False[-0.0242529], False[-0.455023], False[-0.0248755], 
 False[-0.775284], False[-2.32158], False[-1.13717], False[-0.180221],
  False[-0.00208826], False[-0.871422], False[-2.64331], 
 False[-2.01074], False[-1.61355], False[-0.889881], False[-1.32362], 
 False[-0.853051], False[0.0164339], False[-0.532954], 
 False[-0.0142351], False[-0.490718], False[-0.0788749], 
 False[-1.40026], False[-1.17977], False[-0.684725], False[-0.979492],
  False[-0.0998264], False[0.0117253], False[-0.0318328], 
 False[-0.00674015], False[-0.678779], False[0.011897], 
 False[-1.85557], False[-0.0022005], False[-1.85316], 
 False[-0.261599], False[-0.259921], False[-0.382659], 
 False[-0.698182], False[-0.00345263], False[-0.464352], 
 False[-0.41855], False[0.00594555], False[0.0162726], 
 False[0.0177095], False[0.00314803], False[-0.408368], 
 False[-0.327221], False[-0.791253], False[-1.2185], False[-0.393051],
  False[-0.00369397], False[-0.104074], False[-0.0925481], 
 False[0.000556693], False[0.0168595], False[-1.78105], 
 False[0.00378658], False[-0.862495], False[0.00664707], 
 False[0.013905], False[0.0128052], False[-0.00818028], 
 False[-0.174254], False[-0.52816], False[-0.0266625], 
 False[-0.225035], False[-1.26289], False[-1.20893], False[-1.95891], 
 False[-1.49259], False[-0.276017], False[-0.00488948], 
 False[-0.188929], False[-0.292638], False[-0.12244], 
 False[-0.607744], False[-0.0881013], False[0.0016376], 
 False[-0.0255829], False[-0.507537], False[-0.0423211], 
 False[-0.0189999], False[-0.22005], False[-2.7046], False[-0.791027],
  False[-0.171669], False[-0.688226], False[-0.267235], 
 False[-0.00381888], False[-0.0907534], False[-0.960544], 
 False[-0.245903], False[-1.88333], False[-0.0664739], 
 False[-0.707926], False[-0.154478], False[-0.685221], 
 False[-1.41186], False[-1.39915], False[-2.39255], False[-0.373694], 
 False[-0.478494], False[-0.836916], False[-0.647668], 
 False[-0.035626], False[-0.642229], False[-0.229473], 
 False[-0.291583], False[0.00195234], False[-2.07873], 
 False[-0.147479], False[0.00906507], False[-0.000325938], 
 False[-0.0834076], False[-0.727308], False[-0.449317], 
 False[-1.17985], False[-0.173304], False[-1.19105], False[-0.628425],
  False[-1.20513], False[0.00145278], False[-0.0100417], 
 False[-0.0637946], False[-0.153916], False[-1.59527], 
 False[-0.22821], False[-0.234515], False[-4.27198], 
 False[-0.0059489], False[-0.432367], False[-0.00961057], 
 False[-0.355355], False[0.0201422], False[-1.77883], 
 False[0.0207421], False[-0.0989058], False[-2.01456], 
 False[-0.605284], False[-0.130414], False[-1.84141], 
 False[-0.0831946], False[-0.338782], False[0.0114748], 
 False[-0.833641], False[-0.0000860719], False[-0.500935], 
 False[-0.788605], False[-0.73607], False[-1.65248], False[-0.061852],
  False[-0.291236], False[-0.0297162], False[-0.91426], 
 False[-0.0796188], False[-0.195562], False[-0.150076], 
 False[-0.757872], False[-2.41862], False[-0.002453], 
 False[0.000865947], False[-0.0329671], False[-1.1968], 
 False[-2.69099], False[0.0150612], False[-0.0932407], 
 False[-0.763662], False[-0.198425], False[0.00403056], 
 False[-1.17202], False[-0.0409933], False[0.0120298], 
 False[0.0147145], False[-0.0168515], False[-1.10815], 
 False[-0.867545], False[-1.57192], False[-0.527149], 
 False[-0.00533685], False[-0.217121], False[-0.461579], 
 False[-0.416176], False[-0.0071402], False[-0.868621], 
 False[-0.153364], False[-0.673465], False[-1.2067], False[-0.58002], 
 False[-4.06001], False[-1.84126], False[-2.16529], False[-0.763769], 
 False[-0.00362349], False[-0.509015], False[-0.316208], 
 False[-0.889125], False[-0.64095], False[-2.49163], False[-0.32554], 
 False[0.00128368], False[-0.266193], False[-0.606778], 
 False[0.00419558], False[-0.707962], False[-1.13186], 
 False[-0.130949], False[-0.194097], False[-1.09765], 
 False[-0.295783], False[-0.202087], False[-0.26966], False[-1.30364],
  False[-1.45827], False[-1.35061], False[-0.09613], 
 False[0.00597543], False[0.0161533], False[-0.456783], 
 False[-2.59367], False[-1.51397], False[-1.35864], False[-0.0692761],
  False[0.00442931], False[-0.0943894], False[-0.479168], 
 False[-0.31801], False[-0.190837], False[0.00735646], 
 False[-0.389591], False[-2.39789], False[-3.38182], False[-2.23266], 
 False[-0.0337066], False[-1.47864], False[0.00685956], 
 False[0.00745948], False[-1.28781], False[-0.492818], 
 False[-1.82537], False[-0.146747], False[0.0100848], 
 False[-0.855702], False[-0.0504092], False[-1.02756], 
 False[-0.750537], False[0.017486], False[-0.704152], 
 False[-0.228565], False[-0.0170513], False[-0.166408], 
 False[-0.0349592], False[-0.0963348], False[-0.243968], 
 False[-0.000128855], False[-1.66727], False[-0.619114], 
 False[-0.0406403], False[-1.24164], False[-0.0351199], 
 False[-0.28879], False[-2.02277], False[-0.228792], 
 False[-0.0401017], False[-0.175258], False[-0.279141], 
 False[-0.348257], False[-0.420988], False[-0.331322], 
 False[-0.35891], False[-0.0338831], False[-0.0197264], 
 False[-1.92344], False[0.00497437], False[0.00727384], 
 False[-0.513742], False[-0.991607], False[-0.290339], 
 False[-0.0238301], False[-0.00462596], False[-0.917649], 
 False[-0.0100719], False[-1.04578], False[-2.41409], False[-2.18692],
  False[-0.360335], False[-0.0274504], False[-0.148181], 
 False[-3.09082], False[-2.05409], False[0.0129784], False[-0.180149],
  False[0.00225491], False[-0.116477], False[-1.1929], 
 False[-0.0402718], False[0.0176566], False[-0.304467], False[-2.914],
  False[-0.667108], False[-1.24907], False[-0.0671799], 
 False[-1.95864], False[-0.4507], False[-0.129899], False[-0.074453], 
 False[-0.0970041], False[-1.54323], False[-0.0912781], 
 False[-0.411604], False[-0.393324], False[-0.34243], 
 False[0.00941822], False[-1.17967], False[-0.100016], 
 False[-1.55194], False[-0.0203496], False[-0.0750557], 
 False[-0.853625], False[-1.23812], False[0.0122953], 
 False[-0.193852], False[-0.143601], False[-1.30364], 
 False[-0.581421], False[-0.0730455], False[-1.85066], 
 False[-0.486863], False[-0.157061], False[-0.825948], 
 False[-0.128439], False[-0.281131], False[-0.983539], 
 False[-0.0130223], False[-0.000499448], False[0.00536504], 
 False[-0.0732724], False[-1.7384], False[-1.53284], False[-0.156915],
  False[-0.719018], False[-0.454706], False[-0.436659], 
 False[-1.19954], False[-1.32996], False[-0.128242], False[-0.108277],
  False[-0.661337], False[0.0103701], False[-0.0339683], 
 False[-2.11616], False[-0.0088912], False[-2.07795], 
 False[-0.266592], False[-0.0121944], False[-0.168671], 
 False[-4.07034], False[-0.575037], False[-0.307851], 
 False[0.0110567], False[-1.00203], False[-0.656269], 
 False[-0.095518], False[0.00673167], False[-0.801766], 
 False[-0.0201733], False[-0.472709], False[-1.1001], 
 False[-0.444668], False[-0.0471335], False[-1.75372], 
 False[-0.30839], False[-1.49265], False[-0.276798], False[-0.962135],
  False[-2.4591], False[0.00138199], False[-0.304714], 
 False[-0.169685], False[0.0174367], False[-0.928157], 
 False[-0.223522], False[-0.166668], False[-1.60667], 
 False[0.0135634], False[0.0138034], False[-0.487587], 
 False[-0.231461], False[-0.638323], False[-1.29707], 
 False[-0.129521], False[-0.56216], False[0.00279948], 
 False[-0.958523], False[-0.226032], False[-1.34938], 
 False[-0.125281], False[-0.916853], False[-0.292276], 
 False[0.00833051], False[-1.56544], False[-0.148899], 
 False[-0.0448738], False[-0.0251906], False[-0.0089064], 
 False[-0.21952], False[-0.222424], False[-0.340559], 
 False[-0.302422], False[-0.393391], False[-0.409009], 
 False[-1.53943], False[-0.158319], False[-0.346176], 
 False[-0.409718], False[-0.465777], False[-1.12152], 
 False[-0.153125], False[-1.25945], False[-1.07918], False[-0.15136], 
 False[-0.213384], False[-1.78627], False[-0.0574311], 
 False[-0.662022], False[-0.373427], False[-1.48903], 
 False[0.00404545], False[-0.236419], False[-0.701471], 
 False[-0.28745], False[-1.45503], False[-0.0141971], 
 False[0.0202164], False[-0.589638], False[-0.012093], 
 False[0.00566166], False[-0.397392], False[-1.76286], 
 False[0.00558831], False[-1.05903], False[0.000686237], 
 False[-0.665589], False[-2.34399], False[-0.573501], 
 False[-0.293327], False[-0.0499388], False[0.0154478], 
 False[-0.00209036], False[-0.71037], False[-2.30372], 
 False[-0.189421], False[0.0150074], False[-0.130637], 
 False[-0.150213], False[-0.510474], False[0.0110012], 
 False[-2.02226], False[-0.275539], False[-1.74356], False[-0.837231],
  False[-0.974912], False[-0.423378], False[-1.358], False[-1.96089], 
 False[-0.865979], False[-0.0000769021], False[0.0104606], 
 False[0.0148197], False[-0.105884], False[-0.273067], 
 False[-0.000267803], False[0.0151606], False[-0.0999995], 
 False[-0.704426], False[-0.193035], False[0.0013593], 
 False[-0.0679353], False[-0.254207], False[-0.00408009], 
 False[-1.11207], False[-4.07282], False[-0.000614972], 
 False[-0.592221], False[-0.882038], False[-0.154367], 
 False[-0.0439618], False[-0.612721], False[-0.278811], 
 False[-1.00907], False[0.00192309], False[-0.103664], 
 False[-0.105078], False[-2.07276], False[-2.06889], 
 False[-0.0293812], False[-0.731935], False[0.00292436], 
 False[-0.663792], False[-0.866454], False[-0.104195], 
 False[-0.907719], False[-2.97611], False[-0.0474658], 
 False[-1.34445], False[-0.466772], False[-1.35291], False[-0.595197],
  False[-0.515568], False[-0.00814751], False[-0.425608], 
 False[-0.699767], False[-2.14787], False[-0.231324], 
 False[-0.0581978], False[-1.50608], False[-0.131266], False[-3.5905],
  False[-0.256459], False[-0.13331], False[-0.884917], 
 False[-0.602804], False[-0.105517], False[0.00226442], 
 False[-0.760392], False[0.00119885], False[-0.87547], 
 False[-1.59599], False[0.00996144], False[-2.33036], 
 False[-0.644249], False[-0.210697], False[-0.333687], 
 False[-1.41436], False[-0.181059], False[-0.000481868], 
 False[-2.7087], False[-0.0550426], False[-0.116115], 
 False[-0.107361], False[-0.00380058], False[-0.0244548], 
 False[-0.0155941], False[-0.0552381], False[0.00326701], 
 False[-1.72011], False[-2.83902], False[-0.183771], False[-1.69215], 
 False[-0.173938], False[-0.32818], False[0.00109128], 
 False[-0.0440693], False[-0.177284], False[0.00951628], 
 False[-0.607109], False[-1.5914], False[-0.0884484], False[-1.33381],
  False[-0.218346], False[-0.609576], False[0.0129393], 
 False[-0.949788], False[-0.497077], False[-0.0798102], 
 False[-2.9939], False[-0.069065], False[-4.13418], False[-0.286071], 
 False[-1.48154], False[-0.410853], False[-0.332058], 
 False[-0.000614464], False[0.000322744], False[-0.57889], 
 False[-0.0721005], False[-0.829842], False[-0.000260035], 
 False[-1.4533], False[-0.338013], False[-0.395753], 
 False[0.00477703], False[-0.434754], False[-2.14111], 
 False[-0.202733], False[-0.00277048], False[-2.97927], 
 False[-1.26258], False[0.019476], False[-1.52362], False[-0.42453], 
 False[-0.0102852], False[-0.0251576], False[-0.210695], 
 False[-0.182182], False[-0.779109], False[0.000847528], 
 False[0.00505706], False[-0.8013], False[-0.312283], 
 False[-0.0225157], False[-0.208665], False[-0.584081], 
 False[-0.118317], False[-1.48756], False[-0.77638], 
 False[-0.0557635], False[-1.55892], False[-0.400708], 
 False[-0.474962], False[-0.0655085], False[-0.00275707], 
 False[-0.147234], False[-0.252424], False[-0.460808], 
 False[-1.33209], False[-1.45493], False[-0.0777048], False[-3.37717],
  False[-0.486246], False[-0.46044], False[-1.79706], 
 False[-0.0784229], False[-0.0639341], False[-0.00363611], 
 False[-1.02248], False[-0.441507], False[0.00596572], 
 False[-0.00353296], False[-1.72178], False[-0.00113724], 
 False[-0.177813], False[-0.869225], False[-0.164978], 
 False[-0.0258236], False[-0.343847], False[-0.278804], 
 False[-0.0268539], False[-0.137135], False[-0.905185], 
 False[0.00334052], False[-0.967568], False[0.00439722], 
 False[-0.188672], False[0.00409349], False[-2.15289], False[-0.181], 
 False[0.00124813], False[-0.0680406], False[-0.315535], 
 False[0.0180006], False[-1.43152], False[-0.0113799], 
 False[0.00891805], False[-1.03621], False[-0.46612], 
 False[-0.154673], False[-0.0951426], False[-0.576311], 
 False[-0.131996], False[-0.69482], False[-0.608885], 
 False[-0.391658], False[-0.0415362], False[-1.99641], 
 False[-0.287802], False[-1.93484], False[-0.032253], 
 False[0.0121545], False[0.000663557], False[-0.363362], 
 False[-0.823514], False[0.0020972], False[-1.23435], 
 False[-0.925947], False[0.00672187], False[-0.000939983], 
 False[0.00678163], False[-0.878621], False[-0.560264], 
 False[-0.360444], False[-0.837418], False[-0.330033], 
 False[-0.452738], False[-1.97487], False[-0.290738], False[-2.07511],
  False[-0.196068], False[-0.378351], False[-0.0243992], 
 False[-0.638719], False[-0.676911], False[-0.915209], 
 False[-0.986001], False[-0.47934], False[-0.0831488], 
 False[-1.39198], False[-0.354642], False[-1.42146], False[-2.05832], 
 False[-0.386583], False[-0.664586], False[-0.0599292], 
 False[-0.359885], False[-0.666689], False[-1.28989], 
 False[-0.559967], False[-1.01764], False[0.0108501], 
 False[-0.151123], False[-0.43297], False[-0.101716], 
 False[-0.297555], False[-0.812085], False[-0.0242209], 
 False[-4.42696], False[-0.061419], False[-0.0751292], 
 False[-0.449614], False[-0.0129363], False[-0.0319233], 
 False[-0.63256], False[-1.69204], False[-1.53018], False[-1.82515], 
 False[-2.75749], False[-0.00281322], False[-0.100497], 
 False[-0.677445], False[0.00392437], False[0.000936752], 
 False[-1.60245], False[-0.00140027], False[-2.13674], 
 False[-0.46148], False[-1.17397], False[-0.125242], 
 False[0.00757048], False[0.0195375], False[-0.874105], 
 False[0.0140073], False[-0.0459178], False[-0.515161], 
 False[-0.806806], False[-0.386952], False[-2.09775], 
 False[0.0036675], False[-0.336183], False[-0.875732], 
 False[-0.0125018], False[-0.710613], False[-0.120494], 
 False[-0.844724], False[-1.66851], False[-1.2398]}

How to make a true or false table based on the Q1's table

POSTED BY: d.ji

You are probably misunderstanding a few things.

For Q1: Random values of (x,y) will not satisfy the cardioid equation. SO plugging them into that implicit equation is not going to be useful here. It will be useful for Q2 though. For Q1, you are working too hard. All that's wanted is to get random points in the square.

For Q2: Now figure out how to plug these (x,y) pairs into the inequality that gives the cardioid interior.

Also: A line such as Apply[f, %5, {1}] is not terribly useful in a query. Especially when %5 is not explicitly indicated. Use assignments, such as pointlist = RandomReal[{-1,1},{1000,2}];.

POSTED BY: Daniel Lichtblau
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract