#C9.txt, Maple Code for Lecture 9, of Dr.Z.'s ExpMath class, Spring 2021 Help9:=proc(): print(`RRV(n,K), Ave(X), Mom(X,k) , SA(X,K), Pgf(X,x) `): end: #RRV(n,K): A random random variable on {1, ... n} #where the values are from 0 to K (uniformly) RRV:=proc(n,K) local i,ra: ra:=rand(0..K): [ seq(ra(),i=1..n)]: end: #Ave(X): inputs a RV X (given as list of values where the value of #Mr. or Ms. i is L[i]) outputs the average (alias expectation, alias mean) Ave:=proc(X) local i:add(X[i],i=1..nops(X))/nops(X):end: #Mom(X,k): inputs a RV X (given as list of values where the value of #Mr. or Ms. i is L[i]) outputs the k-th moment about the mean Mom:=proc(X,k) local i,mu: mu:=Ave(X):add((X[i]-mu)^k ,i=1..nops(X))/nops(X): end: #SA(X,K): inputs a discrete r.v. X (given as a list of numbers) and #a pos. integer K outputs a list of length K whose #(i) first entry is the average #(ii) second entry variance #The remaining entries are the scaled-third moment (about the mean) aka skeweness #scaled fourth-moment (about the mean) aka kurtosis and so on #up to the K-th moment SA:=proc(X,K) local i,M,mu,sig2: if not (type(X,list) and type(K,integer) and K>=2) then print(`Bad input`): RETURN(FAIL): fi: mu:=Ave(X,1): sig2:=Mom(X,2): M:=[mu,sig2]: if sig2=0 then RETURN(M): fi: [op(M), seq(evalf(Mom(X,i)/sig2^(i/2)),i=3..K)]: end: #Pgf(X,x): inputs a RV X (given as list of values where the value of #Mr. or Ms. i is L[i]) outputs the prob. generating function of X #using the variable Pgf:=proc(X,x) local i:add(x^X[i],i=1..nops(X))/nops(X):end: #f:=Sum(x^a[i], i=1..n); #diff(f,x)= subs(x=1,Sum(a[i]*x^(i-1),i=1..n))/n; #SAc(f,x,K): The SA(X,x,K) of the rv X such whose Pgf is f of x SAc:=proc(f,x,K) local f1: if subs(x=1,f)=0 then RETURN(0): fi: f1:=f/subs(x=1,f): mu:=subs(x=1,x*diff(f1,x)): #TO BE CONTINUED AS HOMEWORK end: