HP Forums
(49G) chi^2 deviate programme - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: General Software Library (/forum-13.html)
+--- Thread: (49G) chi^2 deviate programme (/thread-4288.html)



(49G) chi^2 deviate programme - Gerald H - 07-03-2015 03:59 PM

Given an integer input N > 2 the programme returns a chi^2 distributed deviate for degrees of freedom N.

Code:

::
  CK1&Dispatch
  BINT1
  ::
    %2
    2DUP
    %>
    NcaseSIZEERR
    %/
    BEGIN
    %RAN
    %PI
    %*
    %TAN
    2DUPSWAP
    %2
    %*
    %1-
    %SQRT
    %*
    3PICK
    %+
    %1-
    DUP
    %0>
    ITE
    ::
      OVER
      %SQ_
      %1+
      4PICK
      %1-
      3PICKOVER
      %/
      %LN
      %*
      5PICK
      %2
      %*
      %1-
      %SQRT
      5ROLL
      %*
      %-
      %EXP
      %*
      %RAN
      %<
      casedrpfls
      SWAPDROPTRUE
    ;
    2DROPFALSE
    UNTIL
    DUP
    %+
  ;
;