contagem.mws

Permutações e Combinações

9/10/2007

>    with(combinat);

Warning, the protected name Chi has been redefined and unprotected

[Chi, bell, binomial, cartprod, character, choose, composition, conjpart, decodepart, encodepart, fibonacci, firstpart, graycode, inttovec, lastpart, multinomial, nextpart, numbcomb, numbcomp, numbpart...
[Chi, bell, binomial, cartprod, character, choose, composition, conjpart, decodepart, encodepart, fibonacci, firstpart, graycode, inttovec, lastpart, multinomial, nextpart, numbcomb, numbcomp, numbpart...

Expansão do Binómio

>    for n from 1 to 7 do

>       sort(expand((x+y)^n));

>    od;

x+y

x^2+2*x*y+y^2

x^3+3*x^2*y+3*x*y^2+y^3

x^4+4*x^3*y+6*x^2*y^2+4*x*y^3+y^4

x^5+5*x^4*y+10*x^3*y^2+10*x^2*y^3+5*x*y^4+y^5

x^6+6*x^5*y+15*x^4*y^2+20*x^3*y^3+15*x^2*y^4+6*x*y^5+y^6

x^7+7*x^6*y+21*x^5*y^2+35*x^4*y^3+35*x^3*y^4+21*x^2*y^5+7*x*y^6+y^7

Triângulo de Pascal

>    for n from 1 to 9 do

>       seq(binomial(n,k),k=0..n);

>    od;

1, 1

1, 2, 1

1, 3, 3, 1

1, 4, 6, 4, 1

1, 5, 10, 10, 5, 1

1, 6, 15, 20, 15, 6, 1

1, 7, 21, 35, 35, 21, 7, 1

1, 8, 28, 56, 70, 56, 28, 8, 1

1, 9, 36, 84, 126, 126, 84, 36, 9, 1

Combinações

>    randcomb(3,2);

{1, 2}

>    numbcomb(3,2);

3

>    numbcomb(3,3);

1

>    with(combstruct);

[agfeqns, agfmomentsolve, agfseries, allstructs, count, draw, finished, gfeqns, gfseries, gfsolve, iterstructs, nextstruct]

>    allstructs(Combination([a,b,c]), size=2);

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

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

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

>    allstructs(Combination([a,b,c]), size=3);

[[a, b, c]]

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

[[a, b, c]]

>    allstructs(Combination([1,2,3,4,5]), size=3);

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

>    allstructs(Combination([1,2,3,4,5,6,7]), size=3);

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

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

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

Permutações

>    allstructs(Permutation([1,2,3,4]));

[[1, 2, 3, 4], [1, 2, 4, 3], [1, 3, 2, 4], [1, 3, 4, 2], [1, 4, 2, 3], [1, 4, 3, 2], [2, 1, 3, 4], [2, 1, 4, 3], [2, 3, 1, 4], [2, 3, 4, 1], [2, 4, 1, 3], [2, 4, 3, 1], [3, 1, 2, 4], [3, 1, 4, 2], [3, ...
[[1, 2, 3, 4], [1, 2, 4, 3], [1, 3, 2, 4], [1, 3, 4, 2], [1, 4, 2, 3], [1, 4, 3, 2], [2, 1, 3, 4], [2, 1, 4, 3], [2, 3, 1, 4], [2, 3, 4, 1], [2, 4, 1, 3], [2, 4, 3, 1], [3, 1, 2, 4], [3, 1, 4, 2], [3, ...

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

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

>    numbperm(3, 2); numbperm(3, 3);

6

6

>    numbcomb(40,6);

3838380

Exemplo 2 (Lotaria)

>    print(`n, casos possíveis, probabilidade`);

>    for n from 30 to 50 do

>        n, numbcomb(n,6), evalf(1/numbcomb(n,6));

>    od;

`n, casos possíveis, probabilidade`

30, 593775, .1684139615e-5

31, 736281, .1358177109e-5

32, 906192, .1103518901e-5

33, 1107568, .9028791009e-6

34, 1344904, .7435474948e-6

35, 1623160, .6160822100e-6

36, 1947792, .5134018417e-6

37, 2324784, .4301474890e-6

38, 2760681, .3622294644e-6

39, 3262623, .3065018545e-6

40, 3838380, .2605265763e-6

41, 4496388, .2224007359e-6

42, 5245786, .1906292022e-6

43, 6096454, .1640297786e-6

44, 7059052, .1416620815e-6

45, 8145060, .1227738040e-6

46, 9366819, .1067598296e-6

47, 10737573, .9313091515e-7

48, 12271512, .8148955076e-7

49, 13983816, .7151123842e-7

50, 15890700, .6292988981e-7

>    with(plots);

>    lotaria := proc(a,b::integer)

>       local w,n,i;

>       for n from a to b do

>          w[n]:=1/numbcomb(n,6);

>       od;

>    pointplot({seq([i,w[i]],i=a..b)},symbol=circle,symbolsize=12,color=red,axes=boxed):

>    end:

[animate, animate3d, animatecurve, arrow, changecoords, complexplot, complexplot3d, conformal, conformal3d, contourplot, contourplot3d, coordplot, coordplot3d, cylinderplot, densityplot, display, displ...
[animate, animate3d, animatecurve, arrow, changecoords, complexplot, complexplot3d, conformal, conformal3d, contourplot, contourplot3d, coordplot, coordplot3d, cylinderplot, densityplot, display, displ...
[animate, animate3d, animatecurve, arrow, changecoords, complexplot, complexplot3d, conformal, conformal3d, contourplot, contourplot3d, coordplot, coordplot3d, cylinderplot, densityplot, display, displ...
[animate, animate3d, animatecurve, arrow, changecoords, complexplot, complexplot3d, conformal, conformal3d, contourplot, contourplot3d, coordplot, coordplot3d, cylinderplot, densityplot, display, displ...

>    lotaria(30,50);

[Maple Plot]

>