| 1 |
.PS |
| 2 |
# random.m4 |
| 3 |
gen_init |
| 4 |
NeedDpicTools |
| 5 |
sinclude(tst.dim) |
| 6 |
sinclude(examples.dim) |
| 7 |
s_init(random) |
| 8 |
|
| 9 |
################################################################ |
| 10 |
# hscale(right length,nlabels, |
| 11 |
# minlabel,maxlabel,[T][N]) |
| 12 |
# arg5=T: top axis, N: nolabels |
| 13 |
define(`hscale',`[ define(`hs_nl',`ifelse(`$2',,5,`$2')') |
| 14 |
A: line `$1' ; Start: A.start; End: A.end |
| 15 |
td = 1/(hs_nl-1)*A.len/5 |
| 16 |
define(`hs_ud',`ifinstr(`$5',T,down,up)') |
| 17 |
# Major tics |
| 18 |
for i=1 to hs_nl-2 do { line hs_ud graphsize/20 thick 0.4 \ |
| 19 |
from i/(hs_nl-1) between A.start and A.end } |
| 20 |
# Minor tics |
| 21 |
for i=0 to hs_nl-2 do { Ts: i/(hs_nl-1) between A.start and A.end |
| 22 |
for j=1 to 4 do { line thick 0.4 hs_ud graphsize/20/2 from Ts+(j*td,0) } } |
| 23 |
# Labels |
| 24 |
ifinstr(`$5',N,,`for_(0,eval(hs_nl-1),1, |
| 25 |
`Ts: m4x/(hs_nl-1) between A.start and A.end |
| 26 |
s_box("\small %g",`$3'+m4x/(hs_nl-1)*(`$4'-(`$3'))) \ |
| 27 |
at Ts ifelse(`$5',T,above,below)') ') |
| 28 |
]') |
| 29 |
# vscale(up length,nlabels, |
| 30 |
# minlabel,maxlabel,[R][N] ) |
| 31 |
# arg5=R: right axis, N: nolabels |
| 32 |
define(`vscale',`[ define(`vs_nl',`ifelse(`$2',,5,`$2')') |
| 33 |
A: line `$1' ; Start: A.start; End: A.end |
| 34 |
td = 1/(vs_nl-1)*A.len/5 |
| 35 |
define(`vs_lr',`ifinstr(`$5',R,left,right)') |
| 36 |
# Major tics |
| 37 |
for i=1 to vs_nl-2 do { line vs_lr graphsize/20 thick 0.4 \ |
| 38 |
from i/(vs_nl-1) between A.start and A.end } |
| 39 |
# Minor tics |
| 40 |
for i=0 to vs_nl-2 do { Ts: i/(vs_nl-1) between A.start and A.end |
| 41 |
for j=1 to 4 do { line thick 0.4 vs_lr graphsize/20/2 from Ts+(0,j*td) } } |
| 42 |
# Labels |
| 43 |
ifinstr(`$5',N,,`for_(0,eval(vs_nl-1),1, |
| 44 |
`Ts: m4x/(vs_nl-1) between A.start and A.end |
| 45 |
s_box("\small %g",`$3'+m4x/(vs_nl-1)*(`$4'-(`$3'))) \ |
| 46 |
at Ts ifelse(`$5',R,ljust,rjust)')') |
| 47 |
]') |
| 48 |
# f_gauss(x,mean,stddev) |
| 49 |
define f_gauss`{ std_gauss(($1-($2))/($3))/($3) }' |
| 50 |
define std_gauss`{ expe(-($1)^2/2)/sqrt(twopi_) }' |
| 51 |
################################################################ |
| 52 |
|
| 53 |
[ |
| 54 |
n = 2000 # number of samples |
| 55 |
stddev = 0.25 |
| 56 |
graphsize = 2 |
| 57 |
|
| 58 |
B: box wid graphsize ht graphsize |
| 59 |
# Gemerate n Gaussian random numbers |
| 60 |
randn(z,n,0,stddev) |
| 61 |
m = 0 |
| 62 |
for i=1 to n-1 by 2 do { m +=1; x[m] = z[i]; y[m] = z[i+1] |
| 63 |
dot(at B+(x[m],y[m])) |
| 64 |
} |
| 65 |
|
| 66 |
hscale(right B.wid,5,-1,1) with .Start at B.sw |
| 67 |
hscale(right B.wid,5,-1,1,TN) with .Start at B.nw |
| 68 |
vscale(up B.ht,5,-1,1) with .Start at B.sw |
| 69 |
vscale(up B.ht,5,-1,1,RN) with .Start at B.se |
| 70 |
|
| 71 |
N: box invis wid B.wid ht B.ht with .sw at B.nw+(0,graphsize/10) |
| 72 |
nb = 20 |
| 73 |
binmax = n/5*0.5 |
| 74 |
dx = N.wid/nb |
| 75 |
histbins(x,m,-1,1,nb,hbin) |
| 76 |
for i=0 to nb-1 do { line up hbin[i]/binmax * N.ht \ |
| 77 |
from N.sw+((0.5+i)*dx,0) thick dx/(1bp__) outlined "gray" } |
| 78 |
box wid N.wid ht N.ht at N |
| 79 |
# vscale(up N.ht,5,0,1) with .Start at N.sw |
| 80 |
|
| 81 |
E: box invis wid B.wid ht B.ht with .sw at B.se+(graphsize/10,0) |
| 82 |
nb = 20 |
| 83 |
binmax = n/5*0.5 |
| 84 |
dy = E.ht/nb |
| 85 |
histbins(y,m,-1,1,nb,vbin) |
| 86 |
for i=0 to nb-1 do { line right vbin[i]/binmax * E.wid \ |
| 87 |
from E.sw+(0,(0.5+i)*dy) thick dy/(1bp__) outlined "gray" } |
| 88 |
box wid E.wid ht E.ht at E |
| 89 |
# hscale(right E.wid,5,0,1) with .Start at E.sw |
| 90 |
|
| 91 |
ng = 16 |
| 92 |
for i=0 to ng do { x = i/ng*N.wid |
| 93 |
U: x,(f_gauss(x,N.wid/2,stddev)*m*dx)/binmax*N.ht |
| 94 |
X[i]: N.sw+U |
| 95 |
Y[i]: E.nw+(U.y,-U.x) } |
| 96 |
fitcurve(X,ng) |
| 97 |
fitcurve(Y,ng) |
| 98 |
|
| 99 |
] |
| 100 |
#showbox_ |
| 101 |
|
| 102 |
.PE |