[pstricks] psBinomial modifications
halbard7 at aol.com
halbard7 at aol.com
Sun Aug 26 20:26:28 CEST 2007
Dear Herbert,
Here is the \psBinomial code modified as suggested.
One could have \psBinomial{20}{0.3} (0-20 inclusive) or \psBinomial{4,20}{0.3} (4-20 inclusive) or even \psBinomial{4,12,20}{0.3} (4-12 inclusive). The possibilities are less limited!
\def\psBinomial{\pst at object{psBinomial}}%
\def\psBinomial at i#1#2{\psBinomial at ii#1,,,\@nil{#2}}%
\def\psBinomial at ii#1,#2,#3,#4\@nil#5{%
?\def\pst at tempA{#2}%
?\ifx\pst at tempA\@empty\psBinomial at iii{0}{#1}{#1}{#5}%
?\else\def\pst at tempA{#3}%
?\ifx\pst at tempA\@empty\psBinomial at iii{#1}{#2}{#2}{#5}%
?\else\psBinomial at iii{#1}{#2}{#3}{#5}\fi\fi}%
\def\psBinomial at iii#1#2#3#4{%
? \begin at SpecialObj%
? \addto at pscode{
??? /scx { \pst at number\psxunit mul } def
??? /scy { \pst at number\psyunit mul } def
??? /m #1 def
??? /n #2 def
??? /N #3 def
??? /p #4 def
??? /dx \psFunc at barwidth 2 div def
??? /q 1 p sub def
??? /kOld dx neg m add def
??? kOld scx 0 moveto?? % starting point
%??? /Y 1 def?? % start value
??? 0 1 m 1 sub {
????? /k exch def?????? % save loop variable
????? k 0 eq
??????? { /Y q N exp def }
??????? { /Y Y N k sub 1 add mul k div p mul q div def }
????? ifelse
??? } for
??? m 1 n {???????????? % n-m+1 times
????? /k exch def?????? % save loop variable
????? k 0 eq
??????? { /Y q N exp def }
??????? { /Y Y N k sub 1 add mul k div p mul q div def }
????? ifelse % recursive definition
%???? 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%
}
This time I have attached a text file of the above code.
Yours
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/20070826/c21b4506/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: psBinomial.tex
Type: application/octet-stream
Size: 1677 bytes
Desc: not available
Url : http://tug.org/pipermail/pstricks/attachments/20070826/c21b4506/attachment.obj
More information about the PSTricks
mailing list