Debian Codegraph @

texmf-dist/dvips/pst-math/pst-math.pro

raw
1 % -*- Mode: Postscript -*-
2 % pst-math.pro --- PostScript header file pst-math.pro
3 %
4 % Author : Christophe JORSSEN
5 % Author : Herbert Voß <[email protected]>
6 % Last Mod : $Date: 2018/12/16 $
7 % Version : 0.65 $
8 %
9 /PI 3.14159265359 def
10 /ENeperian 2.71828182846 def
11 %
12 /DegToRad {PI mul 180 div} bind def
13 /RadToDeg {180 mul PI div} bind def
14 %
15 /COS {RadToDeg cos} bind def
16 /SIN {RadToDeg sin} bind def
17 /TAN {dup SIN exch COS Div} bind def
18 /tan {dup sin exch cos Div} bind def
19 /ATAN {neg -1 atan 180 sub DegToRad} bind def
20 /ACOS {dup dup mul neg 1 add sqrt exch atan DegToRad} bind def
21 /acos {dup dup mul neg 1 add sqrt exch atan} bind def
22 /ASEC {1 exch Div ACOS} bind def
23 /ASIN {neg dup dup mul neg 1 add sqrt neg atan 180 sub DegToRad} bind def
24 /asin {neg dup dup mul neg 1 add sqrt neg atan 180 sub} bind def
25 /ACSC {1 exch Div ASIN} bind def
26 %
27 /EXP {ENeperian exch exp} bind def
28 %
29 /COSH {dup EXP exch neg EXP add 2 div} bind def
30 /SINH {dup EXP exch neg EXP sub 2 div} bind def
31 /TANH {dup SINH exch COSH div} bind def
32 /ACOSH {dup dup mul 1 sub sqrt add ln} bind def
33 /ASINH {dup dup mul 1 add sqrt add ln} bind def
34 /ATANH {dup 1 add exch neg 1 add Div ln 2 div} bind def
35 %
36 %/SINC {dup SIN exch Div} bind def
37 /SINC { dup 0 eq { pop 1 } { dup SIN exch div } ifelse } bind def
38
39 /GAUSS {dup mul 2 mul dup 4 -2 roll sub dup mul exch div neg EXP exch PI mul sqrt div} bind def
40 %
41 /GAMMA { 2 dict begin % hv 2007-08-30
42 /z exch def
43 1.000000000190015 % p(0)
44 0 1 5 { % on stack is 0 1 2 3 4 5
45 dup % n-1 n-1
46 [ 76.18009172947146
47 -86.50532032941677
48 24.0140982483091
49 -1.231739572450155
50 0.1208650973866179E-2
51 -0.5395239384953E-5 ] exch get exch % p(n) n-1
52 1 add z add div % p(n)/(z+n)
53 add % build the sum
54 } for
55 Pi 2 mul sqrt z div mul
56 z 5.5 add z 0.5 add Power mul ENeperian z 5.5 add neg Power mul % Power is controlled exp
57 end } bind def
58 %
59 /GAMMALN {dup dup dup 5.5 add dup ln 3 -1 roll .5 add mul sub neg 1.000000000190015
60 0 1 5 {
61 [76.18009172947146 -86.50532032941677 24.0140982483091 -1.231739572450155
62 .1208650973866179E-2 -.5395239384953E-5 2.5066282746310005] exch get
63 4 -1 roll 1 add dup 5 1 roll div add} for
64 4 -1 roll div 2.5066282746310005 mul ln add exch pop} bind def
65 /BETA {2 copy add GAMMALN neg exch GAMMALN 3 -1 roll GAMMALN EXP} bind def
66 %
67 /HORNER {aload length
68 dup 2 add -1 roll
69 exch 1 sub {
70 dup 4 1 roll
71 mul add exch
72 } repeat
73 pop
74 } bind def
75 %
76 /BESSEL_J0 {dup abs 8 lt {
77 dup mul dup [57568490574 -13362590354 651619640.7 -11214424.18 77392.33017 -184.9052456] HORNER
78 exch [57568490411 1029532985 9494680.718 59272.64853 267.8532712 1] HORNER
79 Div}
80 {abs dup .636619772 exch div sqrt exch dup .785398164 sub exch 8 exch div dup dup mul dup
81 [1 -1.098628627E-2 .2734510407E-4 -.2073370639E-5 .2093887211E-6] HORNER
82 3 index COS mul
83 exch [-.1562499995E-1 .1430488765E-3 -.6911147651E-5 .7621095161E-6 -.934945152E-7] HORNER
84 4 -1 roll SIN mul 3 -1 roll mul neg add mul}
85 ifelse} bind def
86 %
87 /BESSEL_Y0 {dup 8 lt {
88 dup dup mul dup [-2957821389 7062834065 -512359803.6 10879881.29 -86327.92757 228.4622733] HORNER
89 exch [40076544269 745249964.8 7189466.438 47447.26470 226.1030244 1] HORNER
90 Div exch dup ln exch BESSEL_J0 .636619772 mul mul add}
91 {dup .636619772 exch div sqrt exch dup .785398164 sub exch 8 exch div dup dup mul dup
92 [1 -.1098628627E-2 .2734510407E-4 -.2073370639E-5 .2093887211E-6] HORNER
93 3 index SIN mul
94 exch [-.1562499995E-1 .1430488765E-3 -.6911147651E-5 .7621095161E-6 -.934945152E-7] HORNER
95 4 -1 roll COS mul 3 -1 roll mul add mul}
96 ifelse} bind def
97 %
98 /BESSEL_J1 {dup abs 8 lt {
99 dup dup mul dup 3 -2 roll [72362614232 -7895059235 242396853.1 -2972611.439 15704.48260 -30.16036606] HORNER mul
100 exch [144725228442 2300535178 18583304.74 99447.43394 376.9991397 1] HORNER
101 Div}
102 {dup abs dup .636619772 exch div sqrt exch dup 2.356194491 sub exch 8 exch div dup dup mul dup
103 [1 .183105E-2 -.3516396496E-4 .2457520174E-5 -.240337019E-6] HORNER
104 3 index COS mul
105 exch [.04687499995 6.2002690873E-3 .8449199096E-5 -.88228987E-6 .105787412E-6] HORNER
106 4 -1 roll SIN mul 3 -1 roll mul neg add mul exch dup abs Div mul}
107 ifelse} bind def
108 %
109 /BESSEL_Y1 {dup 8 lt {
110 dup dup dup mul dup [-.4900604943E13 .1275274390E13 -.5153428139E11 .7349264551E9 -.4237922726E7 .8511937935E4] HORNER
111 exch [.2499580570E14 .4244419664E12 .3733650367E10 .2245904002E8 .1020426050E6 .3549632885E3 1] HORNER
112 Div mul exch dup dup ln exch BESSEL_J1 mul exch 1 exch div sub .636619772 mul add}
113 {dup .636619772 exch div sqrt exch dup 2.356194491 sub exch 8 exch div dup dup mul dup
114 [1 .183105E-2 -.3516396496E-4 .2457520174E-5 -.240337019E-6] HORNER
115 3 index SIN mul
116 exch [.04687499995 -.2002690873E-3 .8449199096E-5 6.88228987E-6 .105787412E-6] HORNER
117 4 -1 roll COS mul 3 -1 roll mul add mul}
118 ifelse} bind def
119 %
120 % En cours...
121 /BESSEL_Yn {dup 0 eq {pop BESSEL_Y0}{dup 1 eq {pop BESSEL_Y1}{
122 exch dup BESSEL_Y0 exch dup BESSEL_Y1 exch 2 exch Div {
123 mul 3 -1 roll mul 2 index sub pstack} for
124 } ifelse } ifelse } bind def
125 %
126 /SIMPSON { 1 dict begin %% on stack a b var f ierr Dominik Rodriguez
127 3 index 5 index sub % compute h
128 1 % a b var f ierr h n
129 4 index 7 index def 3 index exec % a b var f ierr h n f(a)
130 5 index 7 index def 4 index exec add % a b var f ierr h n f(a)+f(b)
131 5 index 8 index 4 index 2 div add def 4 index exec % a b var f ierr h n f(a)+f(b) f(a+h/2)
132 exch 1 index 4 mul add 0 % a b var f ierr h n old=f(a+h/2) Estim=f(a)+f(b)+4f(a+h/2) NbLoop
133 { % a b var f ierr h n old Estim NbLoop
134 5 -1 roll 2 div dup 6 1 roll % h<-h/2
135 5 -1 roll 2 mul 5 1 roll % n<-2n
136 % a b var f ierr h n old Estim NbLoop h
137 2 div 10 index add 0 % a b var f ierr h n old Estim NbLoop a+h/2 Cumul
138 5 index {
139 1 index 10 index exch def 8 index exec add exch 6 index add exch
140 } repeat % a b var f ierr h n old Estim NbLoop a+nh/2 Cumul
141 exch pop % a b var f ierr h n old Estim NbLoop New
142 2 index 1 index 4 mul 6 -1 roll 2 mul sub sub % a b var f ierr h n Estim NbLoop New Diff
143 4 -1 roll 2 mul 1 index sub 4 1 roll % a b var f ierr h n Estim NbLoop New Diff
144 exch 4 1 roll % a b var f ierr h n old Estim NbLoop Diff
145 5 index 6 div mul abs 6 index lt { exit } if
146 1 add dup 9 eq { exit } if
147 } loop % a b var f ierr h n old Estim NbLoop
148 exch 5 -1 roll 6 div mul mark 10 2 roll cleartomark
149 end
150 } def
151 % ------------------------------------ math stuff ----------------------------------
152 %
153 % Matrix A in arrays of rows A[[row1][row2]...]
154 % with [row1]=[a11 a12 ... b1]
155 % returns on stack solution vector X=[x1 x2 ... xn]
156 /SolveLinEqSystem { % on stack matrix M=[A,b] (A*x=b)
157 10 dict begin % hold all ocal
158 /A exch def
159 /Rows A length def % Rows = number of rows
160 /Cols A 0 get length def % Cols = number of columns
161 /Index [ 0 1 Rows 1 sub { } for ] def % Index = [0 1 2 ... Rows-1]
162 /col 0 def
163 /row 0 def
164 /PR Rows array def % PR[c] = pivot row for row row
165 { % starts the loop, find pivot entry in row r
166 col Cols ge row Rows ge or { exit } if % col < Cols and row < Rows else exit
167 /pRow row def % pRow = pivot row
168 /max A row get col get abs def % get A[row[col]], first A[0,0]
169 row 1 add 1 Rows 1 sub { % starts for loop 1 1 Rows-1
170 /j exch def % index counter
171 /x A j get col get abs def % get A[j[r]]
172 x max gt { % x>max, then save position
173 /pRow j def
174 /max x def
175 } if
176 } for % now we have the row with biggest A[0,1]
177 % with pRow = the pivot row
178 max 0 gt { % swap entries pRow and row in i
179 /tmp Index row get def
180 Index row Index pRow get put
181 Index pRow tmp put % and columns pRow and row in A
182 /tmp A row get def
183 A row A pRow get put
184 A pRow tmp put % pivot
185 /row0 A row get def % the pivoting row
186 /p0 row0 col get def % the pivot value
187 row 1 add 1 Rows 1 sub { % start for loop
188 /j exch def
189 /c1 A j get def
190 /p c1 col get p0 div def
191 c1 col p put % subtract (p1/p0)*row[i] from row[j]
192 col 1 add 1 Cols 1 sub { % start for loop
193 /i exch def
194 c1 dup i exch % c1 i c1
195 i get row0 i get p mul sub put
196 } for
197 } for
198 PR row col put
199 /col col 1 add def
200 /row row 1 add def
201 }{ % all zero entries
202 /row row 1 add def % continue loop with same row
203 } ifelse
204 } loop
205 /X A def % solution vector
206 A Rows 1 sub get dup
207 Cols 1 sub get exch
208 Cols 2 sub get div
209 X Rows 1 sub 3 -1 roll put % X[n]
210 Rows 2 sub -1 0 { % for loop to calculate X[i]
211 /xi exch def % current index
212 A xi get % i-th row
213 /Axi exch def
214 /sum 0 def
215 Cols 2 sub -1 xi 1 add {
216 /n exch def
217 /sum sum Axi n get X n get mul add def
218 } for
219 Axi Cols 1 sub get % b=Axi[Cols-1]
220 sum sub % b-sum
221 Axi xi get div % b-sum / Axi[xi]
222 X xi 3 -1 roll put % X[xi]
223 } for
224 X
225 end
226 } def
227 %
228 /c@_0 2.515517 def
229 /c@_1 0.802853 def
230 /c@_2 0.010328 def
231 /d@_1 1.432788 def
232 /d@_2 0.189269 def
233 /d@_3 0.001308 def
234 /norminv {
235 5 dict begin
236 neg 1 add 1 exch div ln 2 mul sqrt
237 /t exch def
238 /t2 t dup mul def
239 /t3 t2 t mul def
240 c@_0 c@_1 t mul add c@_2 t2 mul add 1 d@_1 t mul add
241 d@_2 t2 mul add d@_3 t3 mul add div neg t add
242 end
243 } def
244 %end{norminv Michael Sharpe}
245 %
246 %
247 % END pst-math.pro