Zurück zum Inhaltsverzeichnis

Kapitel 21

Kombinatorik

> restart:

> 5!;

120

> binomial(12,10);

66

> binomial(a+3,a);

binomial(a+3,a)

> expand(%);

1/6*a^3+a^2+11/6*a+1

> with(combinat);

Warning, the protected name Chi has been redefined and unprotected

[Chi, bell, binomial, cartprod, character, choose, ...
[Chi, bell, binomial, cartprod, character, choose, ...
[Chi, bell, binomial, cartprod, character, choose, ...

> multinomial(12,5,5,2);

16632

> 12! / (5! * 5! *2!);

16632

> choose( [a,b,b,c]), numbcomb( [a,b,b,c]);

[[], [b], [c], [b, c], [b, b], [b, b, c], [a], [a, ...

> choose( [a,b,b,c],2), numbcomb( [a,b,b,c], 2);

[[a, b], [a, c], [b, c], [b, b]], 4

> randcomb( [a,b,b,c],2);

[b, b]

> permute([a,b,b,c]), numbperm([a,b,b,c]);

[[a, b, b, c], [a, b, c, b], [a, c, b, b], [b, a, b...
[[a, b, b, c], [a, b, c, b], [a, c, b, b], [b, a, b...

> permute([a,b,b,c],2), numbperm([a,b,b,c],2);

[[a, b], [a, c], [b, a], [b, b], [b, c], [c, a], [c...

> randperm([a,b,b,c]);

[b, c, b, a]

> cproc:=cartprod( [[a,b,c],[x,y],[1,2]]):

> l:=[]: while not cproc[finished] do l:=[op(l),cproc[nextvalue]()]: od: l;

[[a, x, 1], [a, x, 2], [a, y, 1], [a, y, 2], [b, x,...
[[a, x, 1], [a, x, 2], [a, y, 1], [a, y, 2], [b, x,...
[[a, x, 1], [a, x, 2], [a, y, 1], [a, y, 2], [b, x,...

> partition(6), numbpart(6);

[[1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 2], [1, 1, 2, 2],...
[[1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 2], [1, 1, 2, 2],...

> composition(6,2), numbcomp(6,2);

{[2, 4], [5, 1], [3, 3], [4, 2], [1, 5]}, 5

Werkzeuge zur beschreibenden Statistik

> restart:with(stats): with(describe):

> data:=[ 2,3,4,Weight(5,4),missing,Weight(1..4,3) ];

data := [2, 3, 4, Weight(5,4), missing, Weight(1 .....

> mean(data), (2+3+4+5*4+(1+4)/2*3)/10;

73/20, 73/20

> importdata("c:\\kofler\\cd_neu_d\\R6\\Examples\\part3\\statdata.dat");

1., 2., 3.5, 1., missing, 4., 2., 7., 3., 9., 8., 7...

> importdata("c:\\kofler\\cd_neu_d\\R6\\Examples\\part3\\statdata.dat",3);

[1., 1., 2., 9.], [2., missing, 7., 8.], [3.5, 4., ...

> with(transform):

Warning, the protected name apply has been redefined and unprotected

> tst:=[Weight(1..3,4), 3..4, Weight(4..7,4), 8];

tst := [Weight(1 .. 3,4), 3 .. 4, Weight(4 .. 7,4),...

> statvalue(tst);

[1 .. 3, 3 .. 4, 4 .. 7, 8]

> classmark(tst), statvalue(classmark(tst));

[Weight(2,4), 7/2, Weight(11/2,4), 8], [2, 7/2, 11/...

> frequency(tst), cumulativefrequency(tst);

[4, 1, 4, 1], [4, 5, 9, 10]

> apply[sin](tst);

[Weight(sin(1) .. sin(3),4), sin(3) .. sin(4), Weig...

> multiapply[(x,y)->x*y]([[1,2,3], [4,5,6]]);

[4, 10, 18]

> scaleweight[1/count(tst)](tst);

[Weight(1 .. 3,2/5), Weight(3 .. 4,1/10), Weight(4 ...

> statsort( [6,missing,3,Weight(4..5,2)] );

[3, Weight(4 .. 5,2), 6, missing]

> split[3]([1,2,3,4,5,6]);

[[1, 2], [3, 4], [5, 6]]

> split[4]([1,2,3,4,5,6]);

[[1, Weight(2,1/2)], [Weight(2,1/2), 3], [4, Weight...

> tallyinto( [1,2,2,2,3,4,5,6,6], [1..3,3..4,4..7]);

[Weight(1 .. 3,4), 3 .. 4, Weight(4 .. 7,4)]

> tst:=[seq(rand(100)(), n=1..100)];

tst := [81, 70, 97, 63, 76, 38, 85, 68, 21, 9, 55, ...
tst := [81, 70, 97, 63, 76, 38, 85, 68, 21, 9, 55, ...
tst := [81, 70, 97, 63, 76, 38, 85, 68, 21, 9, 55, ...
tst := [81, 70, 97, 63, 76, 38, 85, 68, 21, 9, 55, ...

> bins:=[seq(10*n..10*n+10 ,n=0..9)];

bins := [0 .. 10, 10 .. 20, 20 .. 30, 30 .. 40, 40 ...

> tallyinto(tst,bins);

[Weight(40 .. 50,10), Weight(50 .. 60,7), Weight(60...
[Weight(40 .. 50,10), Weight(50 .. 60,7), Weight(60...

> frequency(%);

[10, 7, 12, 13, 10, 14, 11, 8, 9, 6]

Datenanalyse

> restart:with(stats): with(describe);

[coefficientofvariation, count, countmissing, covar...
[coefficientofvariation, count, countmissing, covar...
[coefficientofvariation, count, countmissing, covar...

> tst:= [1,2,3,Weight(4..6,2),Weight(missing,2)]:

> count(tst), countmissing(tst);

5, 2

> range(tst);

1 .. 6

> mean(tst);

16/5

> quadraticmean(tst);

8/5*sqrt(5)

> standarddeviation(tst), variance(tst);

8/5, 64/25

> quantile[3/4](tst), quartile[3](tst),percentile[75](tst);

39/8, 39/8, 39/8

> tst:=[1,2,3,4],[2,4,5,6]:

> linearcorrelation(tst ); evalf(%);

13/35*sqrt(7)

.9827076297

> covariance(tst); evalf(%);

13/8

1.625000000

Grafische Darstellung

> restart:

> with(stats): with(statplots): with(transform):

> with(random): with(describe): with(plots):

Warning, the protected name apply has been redefined and unprotected

Warning, the name poisson has been redefined

Warning, the name changecoords has been redefined

> f:=normald[5,1]: data:=[f(100)]:

> tallyinto(data, [seq(n*0.5..(n+1)*0.5,n=1..20)]):

> histdata:=scaleweight[1./count(%)](%);

histdata := [Weight(4.5 .. 5.0,.2000000000), Weight...
histdata := [Weight(4.5 .. 5.0,.2000000000), Weight...
histdata := [Weight(4.5 .. 5.0,.2000000000), Weight...
histdata := [Weight(4.5 .. 5.0,.2000000000), Weight...
histdata := [Weight(4.5 .. 5.0,.2000000000), Weight...
histdata := [Weight(4.5 .. 5.0,.2000000000), Weight...

> p1:=histogram(histdata,color=green):

> fpdf:=statevalf[pdf,f]:

> p2:=plot(fpdf(x), x=0.5..10):

> display( [p1, p2] );

[Maple Plot]

> matrixplot( [[1,2,3], [3,4,5]], heights=histogram, axes=framed, gap=0.2, style=patch, shading=none, ambientlight=[0.5,0.5,0.5], light=[45,45,0.5, 0.5, 0.5]);

[Maple Plot]

> datax:=[normald[5,1](100)]:

> datay:=[normald[7,2](100)]:

> scatterplot(datax,datay,color=navy);

[Maple Plot]

> scatterplot(datax,datay,format=quantile);

[Maple Plot]

> scatterplot(datax);

[Maple Plot]

> scatterplot(datax,format=jittered);

[Maple Plot]

> scatterplot([1, 2$5, 3$3,4$10, 5, 6$4],format=stacked);

[Maple Plot]

> boxplot(datax);

[Maple Plot]

> boxplot(datax,format=notched,shift=5,width=2);

[Maple Plot]

> p1:=scatterplot(datax, datay):

> p2:=xyexchange(boxplot(datax,shift=18,width=1)):

> p3:=boxplot(datay,format=notched,shift=8,width=0.5):

> display( [p1,p2,p3] , view=[0..9,0..19]);

[Maple Plot]

>

> yscale := (scl,x)-> xyexchange(xscale(scl,xyexchange(x))):

> tallyinto(datay, [seq(n..n+1, n=-2..18)]):

> histdata:=scaleweight[1./count(%)](%):

> p1:=histogram(histdata):

> p2:=yshift(0.3,yscale(0.05,scatterplot(datay,format=jittered))):

> display([p1,p2], axes=boxed);

[Maple Plot]

Diskrete und stetige Verteilungen

> restart:with(stats): with(statevalf):

> f1:=statevalf[pdf,normald[0,1]]:

> f2:=statevalf[cdf,normald[0,1]]:

> f3:=statevalf[icdf,normald[0,1]]:

> f1(1), f2(1), f3(0.841);

.2419707244, .8413447460, .9985762706

> f3(f2(3));

3.000000007

> plot({f1(x), f2(x)}, x=-4..4);

[Maple Plot]

> plot(f3(x),x=0..1, -3..3);

[Maple Plot]

> statevalf[icdf,normald[90000,20000]](0.8);

106832.4247

> f1:=statevalf[pdf,exponential[1]]:

> plot(f1(x), x=0..4);

[Maple Plot]

> f1:=statevalf[pdf,lognormal]:

> plot(f1(x), x=0..4);

[Maple Plot]

> f1:=statevalf[pf,poisson[5]]:

> seq(f1(n), n=1..10);

.3368973500e-1, .8422433749e-1, .1403738958, .17546...
.3368973500e-1, .8422433749e-1, .1403738958, .17546...

> plot(f1(floor(x)), x=1..10,numpoints=1000);

[Maple Plot]

Zufallszahlen

> restart:

> with(stats): with(random): with(statplots): with(plots): with(statevalf):

Warning, the name poisson has been redefined

Warning, the name changecoords has been redefined

> normald[10,1](3);

11.17583957, 9.436635869, 10.23539400

> f:=normald[10,1](generator[20]):

> f(), f(), f();

9.2831894555035602721, 9.2577082117416025222, 11.63...

> yscale := (scl,x)-> xyexchange(xscale(scl,xyexchange(x))):

> f:=normald[5,2]:

> p1:=plot( statevalf[pdf,f](x), x=-2..12):

> p2:=yshift(0.2,yscale(0.03,scatterplot( [f(300)],format=jittered ))):

> display([p1,p2]);

[Maple Plot]

> f:=beta[5,2]:

> p1:=plot( statevalf[pdf,f](x), x=0..1):

> p2:=yshift(2.6,yscale( 0.2,scatterplot([f(300)],format=jittered ))):

> display([p1,p2]);

[Maple Plot]

>

Zurück zum Inhaltsverzeichnis