#OK to post homework #Zidong Zhang, 28/2/2021, Assignment 11 #RandPnk(n,k):that genearte unoformly at random, a partion of n with largest part k, RandPnk := proc(n,k) local k1,pn1: if k>n then RETURN([]): fi: if n = k then RETURN([n]): fi: k1:= rand(1..(n-k))(): pn1:=RandPnk(n-k, k1): RETURN([op(pn1),k]): end: #RandPn(n):that genearte, unoformly at random, a partion of n RandPn := proc(n) local die,k: die:= [seq(pnk(n,i), i = 1 ..n )]: k := LD(die): RandPnk(n,k): end: #EstStatAnalOfLargestPart(n,K,N): that inputs a positive integer n and a fairly large K, and (using previous functions), estimaes the expectation, variance, and the 3rd- through K-th scaled moments, of the r.v. "number of parts" when running over the sample space of (integer) partitions of n. ########I'm guessing that you mean we repeat it K times and from 3 to N-th scaled moments. But I'm not sure, but I shall try this direction. EstStatAnalOfLargestPart := proc(n ,K ,N) local mu , var, L, X: X := [seq(nops(RandPn(n)), i = 1 .. K)]: mu := Ave(X): var:=Mom(X,2): L := [mu,var]: if var = 0 then RETURN(L): fi: [op(L) , seq(evalf(Mom(X,i)/var^(i/2)) , i =3 .. N) ] end: ## I run the program several times and find that the mean is about 5.93 # and the variance is about 3.27 they are very close to each other. ####when I run EstStatAnalOfLargestPart(200,10000,6), the 3rd moment and the 4th moment is has more fluctuation than mean and variance, especially 4th moment. #pnSeqGFt(N,t) : that inputs N, and a variable t, and outputs the first N+1 (starting at n=0) of the sequence {Pn(t)} mentioned in the previous problem. pnSeqGFt := proc(N,t) local L , i , p ,Pn1 : L:=[1]: for i from 1 to N do Pn1:= Pn(i): p := add(t^nops(Pn1[j]), j =1 .. nops(Pn1)): L:=[op(L) , p]: od: L: end: ######################from C7 and C11 LD:=proc(L) local n,i,su,r: n:=nops(L): r:=rand(1..convert(L,`+`))(): su:=0: for i from 1 to n do su:=su+L[i]: if r<=su then RETURN(i): fi: od: end: pnk:=proc(n,k) local k1: option remember: if not (type(n,integer) and type(k,integer) and n>=1 and k>=1 )then RETURN(0): fi: if n=k then RETURN(1): else RETURN(add(pnk(n-k,k1),k1=1..min(k,n-k))): fi: end: Ave:=proc(X) local i:add(X[i],i=1..nops(X))/nops(X):end: Mom:=proc(X,k) local i,mu: mu:=Ave(X):add((X[i]-mu)^k ,i=1..nops(X))/nops(X): end: