[pstricks] psPoisson improvement suggestion
halbard7 at aol.com
halbard7 at aol.com
Sat Aug 25 15:38:43 CEST 2007
Dear Herbert
May I submit a code modification to pst-func to bring \psPoisson in line with \psBinomial and allow a recursive
implementation of the Poisson distribution. Here is the relevant code with the suggested changes:
% pst-func.tex
.
.
\def\fileversion{0.49}
\def\filedate{2007/12/23}
.
.
etc
.
\def\psPoisson at i#1#2{%
? \begin at SpecialObj%
? \addto at pscode{
??? /scx { \pst at number\psxunit mul } def
??? /scy { \pst at number\psyunit mul } def
??? /N #1 def
??? /lambda #2 def
??? /elambda Euler #2 neg exp def? % e^-lambda
??? /dx \psFunc at barwidth 2 div def
??? /kOld dx neg def
??? kOld scx 0 moveto?? % starting point
??? /Y elambda def??? % start value
??? 0 1 N {???????????? % N times
????? /k exch def?????? % save loop variable
%%%%%%%% ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? GC modified 2007-08-24
%????? k 0 eq { /kFaculty 1 def }{ /kFaculty kFaculty k mul def } ifelse? % <- - - original
%????? /Y lambda k exp kFaculty div elambda mul def???????????????????????? % <- - - lines
????? k 0 eq { /Y elambda def }{ /Y Y lambda mul k div def } ifelse???????? % <- - - new code here
%%%%%%%% ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? GC modified end
????? kOld scx 0 L kOld scx Y scy L k dx add scx Y scy L
????? \ifPst at markZeros k dx add scx 0 L \fi
????? \ifPst at printValue
??????? gsave \psk at PSfont findfont \psk at fontscale scalefont setfont
??????? Y \psk at valuewidth string cvs
??????? k scx \psk at fontscale 2 div add
??????? Y scy \pst at number\pslabelsep add moveto
??????? 90 rotate show grestore
????? \fi
????? /kOld kOld 1 add def
??? } for
??? \ifPst at markZeros\else k dx add scx 0 L \fi % last line down to x-axis
? }%
? \psk at fillstyle
? \pst at stroke
? \end at SpecialObj%
}
.
.
etc
This now allows \psPoisson{N}{mu} to work with N>26.
Another suggestion if I may. To avoid having to use psclip, how about an implementation of \psBinomial and \psPoisson which limits the output of rectangles on both sides,? for example
?? \psPoisson{M}{N}{mu} which plots for M <= x <= N rather than 0 to N
I am thinking of making changes myself. Would you allow this as useful?
Gerry Coombes
________________________________________________________________________
Get a FREE AOL Email account with unlimited storage. Plus, share and store photos and experience exclusively recorded live music Sessions from your favourite artists. Find out more at http://info.aol.co.uk/joinnow/?ncid=548.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://tug.org/pipermail/pstricks/attachments/20070825/027b2192/attachment.html
More information about the PSTricks
mailing list