37363 - Lab/Tutorial 2 Solutions

Scott Alexander

Q1

(a)

P(X=k) = ((n!)/(k!(n-k)!))(p^k)(((1-p))^(n-k))
  ≈(((Sqrt[2π n])(n^n)(e^(-n)))/((Sqrt[2π k])(k^k)(e^(-k))(Sqrt[2π (n-k)])(((n-k))^(n-k))(e^(-n-k))))(p^k)(((1-p))^(n-k))

P(X=n/4) = ((n!)/(((n/4))!(((3n)/4))!))((((1/2)))^(n/4))((((1/2)))^(3n/4))
  = ((n!)/(((n/4))!(((3n)/4))!))(1/(2^n))
  ≈ (((Sqrt[2π n])(n^n)(e^(-n)))/(((Sqrt[2π (n/4)])((((n/4)))^(n/4))(e^(-(n/4))))((Sqrt[2π ((3n)/4)])(((((3n)/4)))^((3n)/4))(e^(-((3n)/4))))))(1/(2^n))

P((Subscript[E, n/4])) = P(X=(n/4))

0.5

1/2

Clear[p,k,n];
k=n/4; p=1/2;
(((Sqrt[2π n])(n^n)(E^(-n)))/((Sqrt[2π k])(k^k)(E^(-k))(Sqrt[2π (n-k)])(((n-k))^(n-k))(E^(-(n-k)))))(p^k)(((1-p))^(n-k))//FullSimplify

(b)

pTrue[n_]:=((n!)/((n/4)!(3n/4)!))((((1/2)))^n);
pApprox[n_]:=(((2^((3/2)+n))×(3^(-(1/2)-((3 n)/4))))/(Sqrt[n π]));
n1=(10^2);
pApprox[n1]/pTrue[n1]//N
n2=(10^4);
pApprox[n2]/pTrue[n2]//N

(c)

The hint gives two equations in two unknowns
t((Subscript[n, 1])) = C (Subscript[n, 1]^α)    and    t((Subscript[n, 2])) = C (Subscript[n, 2]^α).

We have
C = ((t((Subscript[n, 2])))/(Subscript[n, 2]^α)).

α = (Subscript[log, (Subscript[n, 2])/(Subscript[n, 1])])((t((Subscript[n, 2])))/(t((Subscript[n, 1]))))

Hint: Timing[]

out=Timing[Sin[2]];
out[[1]]

n1=(10^5); n2=(10^6);
t1=Timing[pTrue[n1]][[1]];
t2=Timing[pTrue[n2]][[1]];
α=Log[n2/n1,t2/t1];
c=t2/(n2^α);
c((((10^9)))^α)

Q2

(a)

𝔼[Y Z] = (∑_(y=1)^2)(∑_(z=1)^2)y*z*P(Y=y,Z=z)
  =  (∑_(y=1)^2)(∑_(z=1)^2)y*z(∑_(x=1)^2)P(X=x,Y=y,Z=z)
  =  (∑_(y=1)^2)(∑_(z=1)^2)y*z(∑_(x=1)^2)(Subscript[p, X,Y,Z])(x,y,z)

p=Table[0,{2},{2},{2}];
p[[1,1,1]]=5/32; p[[2,1,1]]=4/32; 
p[[1,1,2]]=3/32; p[[2,1,2]]=2/32;
p[[1,2,1]]=7/32; p[[2,2,1]]=6/32;
p[[1,2,2]]=2/32; p[[2,2,2]]=3/32; 

(∑_(y=1)^2)(∑_(z=1)^2)y*z(∑_(x=1)^2)p[[x,y,z]]

Table[i+j,{i,1,8},{j,1,3}]

(b)

𝔼[X|Y=2] = (∑_(x=1)^2)x*P(X=x|Y=2)
  = (∑_(x=1)^2)x*((P(X=x,Y=2))/(P(Y=2)))
  = (((∑_(x=1)^2)x(∑_(z=1)^2)P(X=x,Y=2,Z=z))/((∑_(x=1)^2)(∑_(z=1)^2)P(X=x,Y=2,Z=z)))

(((∑_(x=1)^2)x(∑_(z=1)^2)p[[x,2,z]])/((∑_(x=1)^2)(∑_(z=1)^2)p[[x,2,z]]))

(c)

Q3

We have
(Subscript[f, X,Y])(x,y) = ({{{, ({{(7/54)x (e^(-7y/x-x/3)),, x,y>0}, {0,, otherwise}})}}).

(* maths syntax *)
fXY[x_,y_]:=(7/54)x (E^(-7y/x-x/3));
Plot3D[fXY[x,y],{x,0,4},{y,0,4},AxesLabel->{"x","y","(Subscript[f, X, Y])(x,y)"},PlotRange->All]

(∫_0^∞)(∫_0^∞)fXY[x,y]\[DifferentialD]x\[DifferentialD]y

(* code syntax  *)
fXY[x_,y_]:=7*x*Exp[-7y/x-x/3]/54;Integrate[fXY[x,y],{x,0,Infinity},{y,0,Infinity}]

(a)

(Subscript[f, X])(x) = (∫_(-∞)^∞)(Subscript[f, X,Y])(x,y)dy
  = (∫_(-∞)^0)(Subscript[f, X,Y])(x,y)dy+(∫_0^∞)(Subscript[f, X,Y])(x,y)dy
  = (∫_(-∞)^0)0dy+(∫_0^∞)(7/54)x (e^(-7y/x-x/3))dy
  = (1/54) (e^(-x/3)) (x^2)

(Subscript[f, Y|X])(y|x) = (((Subscript[f, X,Y])(x,y))/((Subscript[f, X])(x))) = (((7/54)x (e^(-7y/x-x/3)))/((1/54) (e^(-x/3)) (x^2)))
  = ((7 (e^(-((7 y)/x))))/x)

Assuming[{x>0,y>0},(∫_0^∞)(7/54)x (E^(-7y/x-x/3))\[DifferentialD]y]

(∫_0^∞)(1/54) (E^(-x/3)) (x^2)\[DifferentialD]x

(((7/54)x (E^(-7y/x-x/3)))/((1/54) (E^(-x/3)) (x^2)))//FullSimplify

(b)

(c)

(d)

(e)