BootcampStat Code Sol
BootcampStat Code Sol
https://ncert.nic.in/ncerts/l/lemh207.pdf
1
4. Find sum(x.^3)/N. This is an estimate of . What is
theoretical
5. Find sum(exp(x))/N. This is an estimate of . What is
theoretical
6. Find sum(x.^2)/N- (sum(x)/N)^2 . This is estimate of Variance .
Find Theoretical variance . Show that
it is 1/12
7. Generate 100000 x 2 U(0,1) random number matrix. Add 'row
wise' to repesent sampling from Z=X1+X2 where X1 and X2
are two IID Random variables( independently and identically
distributed RVs). Draw the histogram. What is the shape it is
tending to?.
8. Generate 1000 x 3 U(0,1) random number matrix. Add 'row wise'
to repesent sampling from Z=X1+X2+X3 . Draw the histogram.
What is the shape it is tending to?.
9. Generate 100000 x 12 U(0,1) random number matrix.
Add 'row wise' and subtract 6 to represent sampling from
Z=(X1+X2+..+X12) - 6 . Draw the histogram. What is the shape it
is tending to?. How close this is to N(0,1) distribution?.
10. Generate 100000 N(0,1) random number vector. Draw the
histogram. What is the shape it is tending to?. Find Matlab
command for drawing 'smooth' histogram and plot again.
11. Generate 100000 Random numbers from following
2
12. Find Theoretical mean and standared deviation using the formula
x=rand(10000,1);
Expected_x=sum(x)/length(x)
Expected_x = 0.5013
3
3. Find sum(x.^2)/N. This is an estimate of . What is theoretical
x=rand(10000,1);
Expected_xsquare=sum(x.^2)/length(x)
Expected_x = 0.3363
x=rand(10000,1);
Expected_xcube=sum(x.^3)/length(x)
Expected_xcube = 0.2440
x=rand(10000,1);
Expected_expox=sum(exp(x))/length(x)
Expected_expox = 1.7154
4
6. Find sum(x.^2)/N- (sum(x)/N)^2 . This is estimate of Variance . Find
Theoretical variance . Show that it is 1/12
N=10000;
x=rand(N,1);
Varx=sum(x.^2)/N-(sum(x)/N)^2
Varx = 0.0842
5
Shape it is tending to Triangular distribution centred around x=1
6
% Histogram tends to symmetric gaussian
7
% Histogram tends to symmetric standared gaussian
x=randn(10000,1);
histogram(x)
8
[f,xi] = ksdensity(x); % Kernel density
figure
plot(xi,f)
x = 1×4
1 2 3 4
Cumprob=cumsum(Prob);
% Cumprob=cumulative prob : [0.3 .5 .6 1]
9
d(1:1000)=0;
for i=1:1000
y=rand();
if y<Cumprob(1)
d(i)=x(1);
elseif y<Cumprob(2)
d(i)=x(2);
elseif y<Cumprob(3)
d(i)=x(3);
else
d(i)=x(4);
end
end
figure
histogram(d,"Normalization","probability")
xbar = 2.5720
Stddev = 1.2839
10
12. Find Theoretical mean and standared deviation using the formula for
the data in 11
2.6000
1.2806
11
12