[comp.sys.handhelds] Probability distribution program for 48SX

ele9050@cdc835.cdc.polimi.it (Luca Radice) (06/26/91)

This is a program for HP-48SX which would be interesting to solve
statistical problem about a lot of distribution equation.
Sorry for my poor english, I hope this explanation clear for
understand the program. Strip the comment and download above here.
----------------------------------------------------------------------
%%HP: T(3)A(D)F(.);
    DIR
      BINO
        DIR
	@ Contents:
	@ Bino: Equation of binomial distribution
	@       Set value of 'n' and 'p' or use solvr.
	@ P: Computes the binomial value for a given k value
	@    using the values of 'n' 'p' stored into the variables.
	@ \Gm: (mu) Calculate the mean of distribution.
	@ \Gs2: (Sigma^2) Standard variation.
	@ G: equation of momentum generator.
	@ RANGE: Computes the cumulative value between
	@        a and b.
          Bino 'n!/(k!*(n-k)!)*p^k*(1-p)^(n-k)'
          P
            \<< \-> k 'n!/(k!*(n-k)!)*p^k*(1-p)^(n-k)' \>>
          \Gm
            \<< 'n*p' \>>
          \Gs2
            \<< 'n*p*(1-p)' \>>
          n 15
          p .12
          G '(1-p+p*e^t)^n'
          RANGE
            \<< \-> a b
              \<< 0 a b FOR T T P + NEXT \>>
            \>>
        END
      POIS
        DIR
	@ Contents:
	@ POIS: Equation of Poisson distribution
	@       Set value of 'np'.
	@ P: Computes the equation value for a given k value
	@    using the value 'np' stored into the variables.
	@ \Gm: (mu) Calculate the mean of distribution.
	@ \Gs2: (Sigma^2) Standard variation.
	@ G: equation of momentum generator.
	@ RANGE: Computes the cumulative value between
	@        a and b.
          POIS '\Gl^k/k!*e^-\Gl'
          P
            \<< \-> k '\Gl^k/k!*e^-\Gl' \->NUM \>>
          \Gm np
          \Gs2 np
          np 3.297
          \Gl np
          G 'e^\Gl(e^t-1)'
          RANGE
            \<< \-> a b
              \<< 0 a b FOR T T P + NEXT \>>
            \>>
        END
      GAUS
        DIR
	@ Contents:
	@ GAUS: Equation of Gauss (and Normal) distribution
	@       Set value of '\Gm'(mean) and '\Gs' (sigma).
	@ F: Computes the equation value for a given X value
	@    using the values of mean and sigma stored into the variables.
	@ P: Computes the area of the upper queue of distribution
	@    between a and +infinite.
	@ G: equation of momentum generator.
	@ P\->X: Computes the X value for a given upper queue area R;
	@        (reverse the equation: ONLY for Standard NORMAL).
	@ RANGE: Computes the area of distribution between
	@        a and b.
          GAUS '1/(\v/(2*\pi)*\Gs)*e^(-(X-\Gm)^2/(2*\Gs^2))'
          G 'e^(\Gm*t)*e^(1/2*\Gs^2*t^2)'
          F
            \<< 'X' STO GAUS \->NUM \>>
          P
            \<< \-> a
              \<< \Gm \Gs 2 ^ a UTPN \>>
            \>>
          \Gm 0
          \Gs 1
          X 5
          P\->X
            \<<
              .000001 \-> H R
              \<< -6 'A' STO 6 'B' STO
                DO B A - 2 / A + 'M' STO M
                  IF 0 1 M UTPN H \>=
                  THEN 'A' STO
                  ELSE 'B' STO
                  END
                UNTIL 0 1 A UTPN H - ABS R \<=
                END
              \>> A { A B M } PURGE
            \>>
          RANGE
            \<< \-> a b
              \<< a P b P - \>>
            \>>
        END
      CHI2
        DIR
	@ Contents:
	@ CHI2: Equation of Chi^2 distribution
	@       Set value of 'v' (freedom degrees).
	@ F: Computes the equation value for a given ki2 value
	@    using the value of 'v' stored into the variable.
	@ P: Computes the area of the upper queue of distribution
	@    between a and +infinite.
	@ G: equation of momentum generator.
	@ CHI\->X: Computes the X value for a given upper queue area R;
	@          (reverse the equation).
	@ \Gs2: (Sigma^2) Standard variation.
          CHI2 '1/(2^(v/2)*(v/2)!)*e^(-ki2/2)*ki2^(v/2-1)'
          F
            \<< 'ki2' STO CHI2 \->NUM \>>
          P
            \<< \-> a
              \<< v a UTPC \>>
            \>>
          v 2
          \Gs2
            \<< '2*v' \->NUM \>>
          ki2 .920044414629
          CHI\->X
            \<<
              .0000001 \-> H R
              \<< 0 'A' STO 200 'B' STO
                DO B A - 2 / A + 'M' STO M
                  IF v M UTPC H \>=
                  THEN 'A' STO
                  ELSE 'B' STO
                  END
                UNTIL v A UTPC H - ABS R \<=
                END
              \>> A { A B M } PURGE
            \>>
          G '1/(1-2*t)^(v/2)'
        END
      GAMM
        DIR
	@ Contents:
	@ GAMM: Equation of Gamma distribution
	@       Set value of '\Gr' and 'k' (freedom degrees).
	@ F: Computes the equation value for a given X value
	@    using the values of '\Gr' and 'k' stored into the variables.
	@ P: Computes the area of distribution
	@    between a and b.
	@ \Gm: (mu) Calculate the mean of distribution.
	@ \Gs2: (Sigma^2) Standard variation.
          GAMM '1/k!*\Gr^k*X^(k-1)*e^(-\Gr*X)'
          F
            \<< 'X' STO GAMM \->NUM \>>
          P
            \<< \-> a b
              \<< a b GAMM 'X' \.S \->NUM 'IERR' PURGE \>>
            \>>
          \Gm
            \<< 'k/\Gr' \->NUM \>>
          \Gs2
            \<< 'k/\Gr^ 2' \->NUM \>>
          k 1
          \Gr 2
          X 1
        END
      STUD
        DIR
	@ Contents:
	@ STUD: Equation of Student (t) distribution
	@       Set value of 'v' (freedom degrees).
	@ F: Computes the equation value for a given t value
	@    using the value of 'v' stored into the variable.
	@ P: Computes the area of the upper queue of distribution
	@    between a and +infinite.
	@ \Gm: (mu) Calculate the mean of distribution.
	@ \Gs2: (Sigma^2) Standard variation.
          STUD '((v+1)/2)!/(\v/(\pi*v)*(v/2)!)*(1/(1+t^2/v)^((v+1)/2))'
          F
            \<< 't' STO STUD \->NUM \>>
          P
            \<< \-> a
              \<< v a UTPT \>>
            \>>
          \Gm 0
          \Gs2
            \<< 'v/(v-2)' \->NUM \>>
          v 4
          t 8
        END
      FISH
        DIR
	@ Contents:
	@ FISH: Equation of Fisher (f) distribution
	@       Set value of 'v' and '\Gl' (freedom degrees).
	@ F: Computes the equation value for a given x value
	@    using the value of 'v' stored into the variable.
	@ P: Computes the area of the upper queue of distribution
	@    between a and +infinite.
	@ \Gm: (mu) Calculate the mean of distribution.
	@ \Gs2: (Sigma^2) Standard variation.
          FISH '\Gl^(\Gl/2)*v^(v/2)*((\Gl+v)/2)!/((\Gl/2)!*(v/2)!)*
                (x^((\Gl-2)/2)/(\Gl*x+v)^((\Gl+v)/2))'
          F
            \<< 'x' STO FISH \->NUM \>>
          P
            \<< \-> a
              \<< \Gl v a UTPF \>>
            \>>
          \Gm
            \<< 'v/(v -2)' \->NUM \>>
          \Gs2
            \<< '2*v^2*(\Gl+v-2)/(\Gl*(v-2)^2*(v-4))' \->NUM \>>
          \Gl 1
          v 5
          x 4
        END
      ESPON
        DIR
	@ Contents:
	@ ESPON: Equation of Esponential distribution
	@        Set value of '\Gm' (mean).
	@ F: Computes the equation value for a given X value
	@    using the value of '\Gm' stored into the variable.
	@ P: Computes the area of the upper queue of distribution
	@    between a and +infinite.
	@ \Gm: (mu) mean of distribution.
          ESPON '1/\Gm*e^-(X/\Gm)'
          F
            \<< 'X' STO ESPON \->NUM \>>
          P
            \<< \-> a
              \<< a .000000002 \Gm * LN \Gm
                NEG * a + ESPON 'X' \.S \->NUM
              \>>
            \>>
          \Gm 5
          X 2
        END
    END
-----------------------------------------------------------------------
Luca Radice Politecnico di Milano Italia. ele9050@cdc835.cdc.polimi.it
--

       Luca Radice                       Politecnico di Milano
ele9050@cdc835.cdc.polimi.it               Centro Di Calcolo