Post Reply 
Little explorations with HP calculators (no Prime)
03-27-2017, 05:29 PM (This post was last modified: 03-27-2017 05:31 PM by pier4r.)
Post: #32
RE: Little explorations with the HP calculators
Quote:Brilliant.org

[Image: mweac3e.png]

For this I wrote a quick program, remembering some quality of the mean that after enough iterations it stabilizes. (I should find the right statement though).

Code:

@there are a couple of unused variables yet

@ Problem: given a square with side one, if we pick points inside the square
@ (or lying on the sides) at random, and we compute the distance between those,
@ what would be the average distance?

@ Approach: instead of math techniques, we could compute this knowing that
@ the average tends to stabilize after some computations.

@ Idea: we also simplify the range of possible value, assuming that the minimum unit is 1
@ and the square as sides of 1000 units.

\<<
  10000 @iterations, to comment out when one wants to use it as input
    @100 iterations shows not sufficient.
  25 @printingEveryXiter
  0 @minValue
  999 @maxValue
  1000 @maxValueForRandom
  0 @partialSumDistances
  0 @executedIterations
  0 @tempX1
  0 @tempY2
  0 @tempX2
  0 @tempY2
  \->
  iterations @ input parameter, integer.
  printingEveryXiter
  minValue
  maxValue
  maxValueForRandom
  partialSumDistances
  executedIterations
  tempX1
  tempY1
  tempX2
  tempY2
  \<<
    1
    iterations
    FOR counter
      @compute first point
      RAND maxValueForRandom * IP 'tempX1' STO
      RAND maxValueForRandom * IP 'tempY1' STO
      @compute second point
      RAND maxValueForRandom * IP 'tempX2' STO
      RAND maxValueForRandom * IP 'tempY2' STO
      
      tempX1 tempX2 - 2 ^
      tempY1 tempY2 - 2 ^
      + \v/
      'partialSumDistances' STO+
      1 'executedIterations' STO+
      
      @ printing the avg
      IF
        counter printingEveryXiter MOD
        0 ==
      THEN
        partialSumDistances executedIterations /
        "iter" counter \->STR +
        \->TAG
      END
    NEXT
    @end result
    partialSumDistances executedIterations /
  \>>
\>>

But i'm not sure about the correctness of the approach. Im pretty sure there is a way to compute this with an integral ad then a closed form too.

Anyway this is the result at the moment:
[Image: YKUkJnq.png]

Wikis are great, Contribute :)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Little explorations with the HP calculators - pier4r - 03-27-2017 05:29 PM



User(s) browsing this thread: 3 Guest(s)