Using Matlab Write code that does the following Here\'s first part of code thoug
ID: 2082983 • Letter: U
Question
Using Matlab
Write code that does the following
Here's first part of code though I am not sure if it is right and I need help writing code for 5 through 7
Please check code given to see if it is right as well
1)%(a)
N=10;
L=100;
X=rand(N,L)
Sn=sum(X)
2)
%(b)
mue=mean(X(1,:))
sigma_square=var(X(1,:))
3)
for n=1:1:L
Zn(n)=(Sn(n)-n.*mue)./(sqrt(sigma_square).*sqrt(n));
end
4)
figure;
n=1:100;
plot(n,Zn);
xlabel('it n ightarrow');
ylabel('it Zn ightarrow');
Central limit theorem 1) Create N random variables (X XN) each with L samples. These should be independent and identically distributed. Generate Sn, which will be the sum of these random variables. 2) Find the mean and variance of X1 e. H and o2. Since the RV's are iid's, H will be the mean of all the other RV's in this set too. You can verify this by finding the mean of a few other variables. 3) Create the random variable Zn by adding N random variables as Sn nu. avn 4) Plot the pdf of Zn 5) Repeat steps 3 and 4 for NJ10, NJ50 and NJ100. For each case, repeat for values of L 100, 1000, 10,000 and 1000,000. 6) Comment on the effects of the various values of Land N. 7) Repeat for each of the three RV's listed below: Uniform random variable Exponential random variable (lambda 0.5) Gaussian random variable (mu J 5, sigma J 2)Explanation / Answer
5)Ans:
In order to repeat the steps 3 and 4 we need to edit the Sn and mue values form step 1 and 2.
So I am writing the overall code for each case in a loop.
Code :
L=[100,1000,10000,1000000];%The different cases of the L values.
N=[10,50,100];% The different cases of the N values.
for i=N(1:end)% To select the one of the N value from the set.
for j=L(1:end)% To select the one of the L value from the set and to calculate it for each N values we placed in inner loop
%1)Ans X=rand(i,j);% To create N random variables
Sn=sum(X);% To generate Sn
%2)Ans mue=mean(X(1,:));
sigma_square=var(X(1,:));
%3)Ans
for n=1:1:j
Zn(n)=(Sn(n)-n.*mue)./(sqrt(sigma_square).*sqrt(n));% To create a random variable Zn
end
%4)Ans
figure;
n=1:i;
plot(n,Zn);% To plot the Zn.
xlabel('it n ightarrow');
ylabel('it Zn ightarrow');
hold on% To hold the current figure
end
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.