my asign
-
Upload
umer-qureshi -
Category
Documents
-
view
220 -
download
0
Transcript of my asign
-
7/28/2019 my asign
1/11
ANS PROBLEM 1:
MATLAB CODE
close all %Close any previously opened window like graph.
clear all %Clear all varibles in workspace.
Trials=2000; %Supposing Number of trials.
for i=1:Trials %Loop
if rand(1,1)
-
7/28/2019 my asign
2/11
OBSERVATION: From the graph it can be concluded that at least 400 trials are must to getan accurate estimate of probability of heads.
ANS PROBLEM 2(a):MATLAB CODE[THE COMPLETE CONCEPT IS TAKEN FROM THE CODE IN TEXT BOOK]close all; %close previously opened window
clear all; %clear ll variables in workspace
randn('state',0) %initialize guassian random no's gnrtr
x=randn(1000, 1); %generate 1000 random #'s
bincenters=[-4:0.5:4]'; %specify bins center positions
bins=length(bincenters); %total no of bins
h=zeros(bins,1); %Generate 0's vector
for i=1:length(x) %dumping random no's into specified bins
for k=1:bins
-
7/28/2019 my asign
3/11
if x(i)>bincenters(k)-0.5/2 & x(i)
-
7/28/2019 my asign
4/11
ANS PROBLEM 2(b):
MATLAB CODE[THE COMPLETE CONCEPT IS TAKEN FROM THE CODE IN TEXT BOOK]close all; %close previously opened wndow
clear all; %clear data in worksapce
randn('state',0) %initialize guassian random number generator
z=randn(2000, 1)+j*randn(2000, 1); %generate complex numbers
Mg_z=sqrt(real(z).^2+imag(z).^2); %magnitude of complex numbers
width_of_PDF=1; %probability density function's width
bincenters=[0.5:0.5:4]'; %specify bins center positions
bins=length(bincenters); %total no of bins
h=zeros(bins,1); %generate 0's vector
for i=1:length(Mg_z) %assigning corresponding values to bins
for k=1 :bins
if Mg_z(i)>bincenters(k)-0.5/2 & Mg_z(i)
-
7/28/2019 my asign
5/11
h(k,1)=h(k,1)+1;
end
end
end
pxest=h/(1000*0.5); %estimated probability
xaxis=[0:0.01:5]';
px=(xaxis/width_of_PDF).*exp((-0.5*xaxis. 2)/width_of_PDF); %true probability
bar(bincenters,pxest,0.5)
hold on
plot(xaxis,px,'r')
legend('estimated','true')
grid;
title(' Rayleigh PDF . ');
xlabel('complex #s.');
-
7/28/2019 my asign
6/11
ylabel('Estimated and True Probability');
GRAPH:
ANS PROBLEM 2(c):
MATLAB CODE[THE COMPLETE CONCEPT IS TAKEN FROM THE CODE IN TEXT BOOK]
close all; %close previously opened wndow
clear all; %clear data in worksapce
randn('state',0) %initialize guassian random number generator
z=randn(1000, 1)+j*randn(1000, 1); %generate complex numbers
Mg_z=sqrt(real(z).^2+imag(z).^2); %magnitude of complex numbers
width_of_PDF=1; %probability density function's width
bincenters=[-3:0.5:3]'; %specify bins center positions
bins=length(bincenters); %total no of bins
h=zeros(bins,1); %generate 0's vector
-
7/28/2019 my asign
7/11
for i=1:length(Mg_z) %assigning corresponding values to bins
for k=1 :bins
if Mg_z(i)>bincenters(k)-0.5/2 & Mg_z(i)
-
7/28/2019 my asign
8/11
ANS PROBLEM 2(d):
MATLAB CODE[THE COMPLETE CONCEPT IS TAKEN FROM THE CODE IN TEXT BOOK]close all; %close previously opened wndow
clear all; %clear data in worksapce
randn('state',0) %initialize guassian random number generator
z=randn(2000, 1)+j*randn(2000, 1); %generate complex numbers
Mg_z=sqrt(real(z).^2+imag(z).^2); %magnitude of complex numbers
width_of_PDF=1; %probability density function's width
Mag_square=Mg_z.^2; %square of magnitude
bincenters=[0.5:0.5:4]'; %specify bins center positions
bins=length(bincenters); %total no of bins
h=zeros(bins,1); %generate 0's vector
for i=1:length(Mag_square) %assigning corresponding values to bins
for k=1 :bins
-
7/28/2019 my asign
9/11
if Mag_square(i)>bincenters(k)-0.5/2 & Mag_square(i)
-
7/28/2019 my asign
10/11
ANS PROBLEM 3:
MATLAB CODE:close all %close previously opened winodw
clear all %clear all data from workspace
randn('state',0)
X1=randn(3e3,1); %3e3 means 3000 random no's
X2=randn(3e3,1);
Y1=X1+(0.1*X2);
Y2=X1+(0.2*X2);
Result=[Y1 Y2];
scatterplot(Result)
title(' Scatter Plot For Y1 and Y2');
xlabel('Y1')
-
7/28/2019 my asign
11/11
ylabel('Y2')
GRAPH:
Conclusion:
If we let Y1=1 then we can say that Y2 is also approximately equal to 1, because if we
see in the zoomed image of scatterplot in above figure we come to know that for Y1=1, the
values of Y2 on vertical axis lie in the range [0.7,1.2] and the average of this interval is
approximately equal to 1. So our conclusion is right.