> #Weiji Zheng, 10/18/2020, Homework12 ; > #OK TO POST HOMEWORK ; > ; > #Q1 ; > #By iterating procedure CP(L1,L2), inM12.txt, write a procedure CPg(L) that inputs a list of lists L=[L1,L2, ...,Lk] of "databases" (represented as lists L1, L2, ..., Lk) and outputs CP(L1,L2, ..., Lk).In particular, CPg([L1,L2]) should output the same as CP(L1,L2) for any two lists of integers L1 and L2 ; > ; > #CP CODE ; > CP:=proc(L1,L2) local i,j,L: > L:=[]: > for i from 1 to nops(L1) do > for j from 1 to nops(L2) do > L:=[op(L),L1[i]+L2[j]]: > od: > od: > L: > > end: > ; > #CPg CODE ; > CPg:=proc(L) local S, j: > option remember: > S := L[1]: > for j from 2 to nops(L) do > S := CP(S, L(j)): > od: > S: > end: > ; > #Q2 ; > #Code neeeded ; > WtEn:=proc(L,x) local i: > add(x^L[i],i=1..nops(L)): > end: > AveClever:=proc(L) local f,x: > f:=WtEn(L,x): > subs(x=1,diff(f,x))/subs(x=1,f): > end: > kthMomentClever:=proc(L,k) local x,mu,f,f1,i: > f:=WtEn(L,x): > mu:=AveClever(L): > f1:=f/x^mu/subs(x=1,f): > for i from 1 to k do > f1:=expand(x*diff(f1,x)): > od: > subs(x=1,f1): > end: > ; > #AveGF Code ; > AveGF := proc(f,x) option remember: subs(x=1,diff(f,x))/subs(x=1,f): end: > evalb(AveGF(WtEn(L,x),x)=AveClever(L)) true ; > ; > #Tried to do kthMomentGF but always get not same ; > ; > #Q3 ; > ; > #Code ; > ; > ScaledMomentGF:= proc(f,x,k) > > end: > ; > #Q4 ; > ; > ;