-5
$\begingroup$

Model the law of distribution of a random vector Xi=(Xi1; Xi2) and vector (min{Xi1; Xi2},max{Xi1; Xi2}) using 100 tests, construct a cloud of points and a regression line on the plane. Random variables Xi1 Xi2 are uniformly distributed in a quadrilateral with vertices (2, 2), (1,-2), (-2,-2), (-2, 2).

n = 100; a = -2; b = 2;
gridData = {};
For[i = 1, i <= n, i++, 
  dist = {RandomVariate[UniformDistribution[{a,b}]], 
    RandomVariate[UniformDistribution[{a,b}]]};
  y = Min[{dist[[1]], dist[[2]]}] ; z = Max[{dist[[1]], dist[[2]]}];
  gridData = Append[gridData, {dist[[1]], dist[[2]], y, z}]];
gridlabel = {"\[Xi]1", "\[Xi]2", "min", "max"};
GRIDDATA = {gridlabel}~Join~gridData[[1 ;; 100]];
Grid[GRIDDATA, Frame -> All, FrameStyle -> Gray]
Table\[Xi] = Table[{GRIDDATA[[n, 1]], GRIDDATA[[n, 2]]}, {n, 100}];
Print["Point cloud"];
Show[ListPlot[Table\[Xi]], PlotRange -> All, 
 AxesLabel -> {Subscript[x, 1], Subscript[x, 2]}]
Table\[Xi]minmax = 
  Table[{GRIDDATA[[n, 3]], GRIDDATA[[n, 4]]}, {n, 100}];
Print["Regression line"];
Show[ListPlot[Table\[Xi]minmax, AxesLabel -> {"y", "z"}, 
  PlotRange -> All], 
 Plot[InverseFunction[Integrate[Integrate[1/14,{x,-2,(y+6)/4}],{y,-2,2}]&][t], {t, 0.0001, 20}]]

I need to construct a uniform distribution in a trapezoid. I don’t understand how to do it, since according to the syntax, a uniform distribution has clear left and right boundaries. Please help me correct my code.

Question to the moderators who closed my question. I wrote the terms of the task. An attempt at my own solution. I'm facing a problem that I can't solve. I am answered by a person who gives a separate example, which cannot help me in any way at all. The benefit of such an answer is 0. The documentation contains 50 examples that are just as useless for my specific case. It also surprises me that I’m already -10 for the question, and +20 for his answer. Despite the fact that I asked a normal question, and he absolutely did not answer it. Please delete this question. To which the person spent a lot of time answering. Apparently about 10 seconds.

$\endgroup$
1
  • 5
    $\begingroup$ Boy... this sure sounds like a homework problem. $\endgroup$ Commented Dec 28, 2023 at 20:58

1 Answer 1

6
$\begingroup$
RandomPoint[Polygon[{{2, 2}, {1, -2}, {-2, -2}, {-2, 2}}]]

Graphics[
 Point[RandomPoint[Polygon[{{2, 2}, {1, -2}, {-2, -2}, {-2, 2}}], 
   10000]]
]
$\endgroup$
6
  • $\begingroup$ I asked you to help me correct the code so that the uniform distribution would be in a trapezoid and not in a rectangle, that is, correct the function dist. You wrote separate code. Are you sure this refers to uniform distribution? I don't see a function here UniformDistribution. $\endgroup$
    – Mark
    Commented Dec 28, 2023 at 20:52
  • 2
    $\begingroup$ It's uniform. See the documentation on RandomPoint. Otherwise, you can transform the points from a uniform distibution on a square: points/.{x_,y_}:>matrix.{x,y} $\endgroup$ Commented Dec 28, 2023 at 21:14
  • 6
    $\begingroup$ I didn't want to fix your code. It is procedural and doesn't translate well to clear Wolfram Language code. $\endgroup$ Commented Dec 28, 2023 at 21:16
  • 3
    $\begingroup$ @Mark - You asked for random points "uniformly distributed in a quadrilateral with vertices (2, 2), (1,-2), (-2,-2), (-2, 2)". This answer does in fact address the question you asked. $\endgroup$
    – MelaGo
    Commented Dec 28, 2023 at 22:25
  • 2
    $\begingroup$ @Mark UniformDistribution[] was the wrong tool for this job. Craig wrote the code you should have written. $\endgroup$
    – Ghoster
    Commented Dec 28, 2023 at 23:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.