#Groundhog day, C4n.txt #introducing proba. distribution Help:=proc() print(` ClassStat,AveS, Expec(P,L)`): print(`PGF(P,L,X) ,MomS(P,L,k), Mom(P,L,k) , sd(P,L) `): end: #gathering statistics about the class #[Name,Gender,Age,Height,EyeColor] ClassStat:=proc() local A: A:= [ [Mingjia,F,25,164,Br], [Anthony,M,21,173,Br], [Aniket,M,21,173,Br], [Abigail,F,22,173,Br], [Nathan,M,24,172,Br], [Sowmya,F,23,155,Br], [Ha,F,27,162,Br], [Kafung,F,27,165,Br], [Matthew,M,21,176,Bl], [Marc,M,25,172,G], [Melissa,F,26,172,Bl], [Collin,M,30,183,Bl], [John,M,26,173,Br], [Elliot,M,18,179,Bl], [Michael,M,44,172,Br], [Alex,M,32,189,Bl], [Doron,M,64, 178,Br] ]: end: #AveS(L): the simple average of a list L AveS:=proc(L) evalf(convert(L,`+`)/nops(L)): end: #Expec(P,L): Expec:=proc(P,L) local i: add(P[i]*L[i],i=1..nops(L)): end: #PGF(P,L,x): the probability generating function of #the random variable L defined on {1, ..., nops(L)} #with prob. dist. P PGF:=proc(P,L,x) local i: add(P[i]*x^(L[i]),i=1..nops(L)): end: #MomS(P,L,k):the k-th straight moment of the r.v. L defined on #prob. space given P MomS:=proc(P,L,k) local i: add(P[i]*L[i]^k,i=1..nops(L)): end: #Mom(P,L,k):the k-th moment about the mean of the r.v. L defined on #prob. space given P Mom:=proc(P,L,k) local i,av: av:=Expec(P,L): add(P[i]*(L[i]-av)^k,i=1..nops(L)): end: #standard deviation of r.v. L with prob. dist. P sd:=proc(P,L) evalf(sqrt(Mom(P,L,2))): end: