Binomialfordeling.
Figuren viser tæthedsfunktionen for binomialfordelingen. Du kan variere på parametrene n og p. Læg mærke til, hvordan søjlerne ændrer sig.
Læg også mærke til, hvordan den approksimerende normalfordeling er tæt på binomialfordelingen for store n.
Figure figure = Position [0,0] Size[x,y*4/5] Origin[x/12,y*3/4] Unit x/24 Color "white";
Axes axes = Color "black";
Grid grid = Color "blue";
//Units units = Color "black";
Label x5 = "5" At [5,0] Offset [0,15] Color "black";
Label x10 = "10" At [10,0] Offset [0,15] Color "black";
Label x15 = "15" At [15,0] Offset [0,15] Color "black";
Label x20 = "20" At [20,0] Offset [0,15] Color "black";
Label y05 = "0.5" At [0,5] Offset [-30,-5] Color "black";
Label y10 = "1.0" At [0,10] Offset [-30,-5] Color "black";
State n = From 1 To 20 Initial 5;
PushButton n_down = Text "<" Action decr n Position [20,y-70] Size [30,25];
Text n_text = "n = n" Offset [150,y-50] Color "black";
PushButton n_up = Text ">" Action incr n Position [280,y-70] Size [30,25];
SlidePot p = From 0 To 1 Initial 0.5 Position [20,y-20] Size [300,0];
Text p_txt = "p = p,2" Offset [350,y-15] Color "blue";
State normal_on = From 0 To 1 Initial 0;
RadioButton show_normal = Text [ "normalfordeling"; "normalfordeling" ]
Action [ set normal_on 1; set normal_on 0]
Position [450,y-70] Size [130,25];
Variable my = n*p;
Variable sigma = sqrt(n*p*(1-p));
Function normalfct( Number x, Number sigma, Number my ) =
1/(sigma*sqrt(2*pi))*exp(-.5*((x-my)/sigma)^2);
Function binomial( Number k, Number n, Number p ) =
product(i,1,k,(n-i+1)/i)*p^k*(1-p)^(n-k);
Line l0 = Start [0,0] Dir 10*[0,binomial(0,n,p)] Size 5 Color "red";
Line l1 = Start [1,0] Dir 10*[0,binomial(1,n,p)] Size 5 Color "red";
Line l2 = Start [2,0] Dir 10*[0,binomial(2,n,p)] Size 5 Color "red";
Line l3 = Start [3,0] Dir 10*[0,binomial(3,n,p)] Size 5 Color "red";
Line l4 = Start [4,0] Dir 10*[0,binomial(4,n,p)] Size 5 Color "red";
Line l5 = Start [5,0] Dir 10*[0,binomial(5,n,p)] Size 5 Color "red";
Line l6 = Start [6,0] Dir 10*[0,binomial(6,n,p)] Size 5 Color "red";
Line l7 = Start [7,0] Dir 10*[0,binomial(7,n,p)] Size 5 Color "red";
Line l8 = Start [8,0] Dir 10*[0,binomial(8,n,p)] Size 5 Color "red";
Line l9 = Start [9,0] Dir 10*[0,binomial(9,n,p)] Size 5 Color "red";
Line l10 = Start [10,0] Dir 10*[0,binomial(10,n,p)] Size 5 Color "red";
Line l11 = Start [11,0] Dir 10*[0,binomial(11,n,p)] Size 5 Color "red";
Line l12 = Start [12,0] Dir 10*[0,binomial(12,n,p)] Size 5 Color "red";
Line l13 = Start [13,0] Dir 10*[0,binomial(13,n,p)] Size 5 Color "red";
Line l14 = Start [14,0] Dir 10*[0,binomial(14,n,p)] Size 5 Color "red";
Line l15 = Start [15,0] Dir 10*[0,binomial(15,n,p)] Size 5 Color "red";
Line l16 = Start [16,0] Dir 10*[0,binomial(16,n,p)] Size 5 Color "red";
Line l17 = Start [17,0] Dir 10*[0,binomial(17,n,p)] Size 5 Color "red";
Line l18 = Start [18,0] Dir 10*[0,binomial(18,n,p)] Size 5 Color "red";
Line l19 = Start [19,0] Dir 10*[0,binomial(19,n,p)] Size 5 Color "red";
Line l20 = Start [20,0] Dir 10*[0,binomial(20,n,p)] Size 5 Color "red";
Line l21 = Start [21,0] Dir 10*[0,binomial(21,n,p)] Size 5 Color "red";
Tex tx1 = "p(k)=\\large{\\binom{n}{k} p^k (1-p)^{n-k}}" Offset [320,60] Color "black";
Tex tx2 = "\\mu= n p = " Offset [320,100] Color "black";
Tex tx3 = "\\sigma = \\sqrt{ n p (1-p) } = " Offset [320,140] Color "black";
Text tx21 = "my,2" Offset [400,115] Color "black" Style "font-size:110%;";
Text tx31 = "sigma,2" Offset [465,158] Color "black" Style "font-size:110%;";
Visibility vis = normal_on == 1;
Graph normalgr = 10*normalfct(x,sigma,my) Size 1.5 Color "black";