Ans Problem 1: Matlab Code
Ans Problem 1: Matlab Code
close all clear all Trials=2000; for i=1:Trials %Close any previously opened window like graph. %Clear all varibles in workspace. %Supposing Number of trials. %Loop
if rand(1,1)<0.5 %Condition X(i,1)=1; else X(i,1)=0; end end vector=ones(size(X));%generate vector of 1's of the size of no of heads R_f=cumsum(X)./cumsum(vector); plot(R_f) grid; title('No. of Trials Required for an Accurate Estimate of Probability') xlabel('Minimum no of Trials Reqd for accuracy') ylabel('Relative Frequency') %Formula for relative frequency . %Tail=0. %Head=1.
GRAPH
OBSERVATION: From the graph it can be concluded that at least 400 trials are must
an accurate estimate of probability of heads.
to get
ANS PROBLEM 2(a): MATLAB CODE[THE COMPLETE CONCEPT IS TAKEN FROM THE CODE IN TEXT BOOK]
close all; clear all; randn('state',0) x=randn(1000, 1); bincenters=[-4:0.5:4]'; bins=length(bincenters); h=zeros(bins,1); %close previously opened window %clear ll variables in workspace %initialize guassian random no's gnrtr %generate 1000 random #'s %specify bins center positions %total no of bins %Generate 0's vector
if x(i)>bincenters(k)-0.5/2 & x(i)<=bincenters(k)+0.5/2%condition h(k,1)=h(k,1)+1; end end end %incrementing the zero vector by 1
%estimated probability
%true Probability
title('True and Estimated PDF for Guassian Rnd Vrble'); ylabel('Estimated and True Probability'); xlabel('Ran.#');
GRAPH:
ANS PROBLEM 2(b): MATLAB CODE[THE COMPLETE CONCEPT IS TAKEN FROM THE CODE IN TEXT BOOK]
close all; clear all; randn('state',0) z=randn(2000, 1)+j*randn(2000, 1); Mg_z=sqrt(real(z).^2+imag(z).^2); width_of_PDF=1; bincenters=[0.5:0.5:4]'; bins=length(bincenters); h=zeros(bins,1); for i=1:length(Mg_z) for k=1 :bins if Mg_z(i)>bincenters(k)-0.5/2 & Mg_z(i)<=bincenters(k)+0.5/2 %close previously opened wndow %clear data in worksapce %initialize guassian random number generator %generate complex numbers %magnitude of complex numbers %probability density function's width %specify bins center positions %total no of bins %generate 0's vector %assigning corresponding values to bins
h(k,1)=h(k,1)+1; end end end pxest=h/(1000*0.5); 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.'); %estimated probability
GRAPH:
ANS PROBLEM 2(c): MATLAB CODE[THE COMPLETE CONCEPT IS TAKEN FROM THE CODE IN TEXT BOOK]
close all; clear all; randn('state',0) z=randn(1000, 1)+j*randn(1000, 1); Mg_z=sqrt(real(z).^2+imag(z).^2); width_of_PDF=1; bincenters=[-3:0.5:3]'; bins=length(bincenters); h=zeros(bins,1); %close previously opened wndow %clear data in worksapce %initialize guassian random number generator %generate complex numbers %magnitude of complex numbers %probability density function's width %specify bins center positions %total no of bins %generate 0's vector
if Mg_z(i)>bincenters(k)-0.5/2 & Mg_z(i)<=bincenters(k)+0.5/2 h(k,1)=h(k,1)+1; end end end pxest=h/(1000*0.5); xaxis=[-3.25:0.01:3.25]; px=1/(3.25-(-3.25)); bar(bincenters,pxest,0.5) hold on plot(xaxis,px,'r') legend('estimated','true') grid; xlabel('complex #s.'); ylabel('Estimated and True Probability'); %true probability %estimated probability
GRAPH:
ANS PROBLEM 2(d): MATLAB CODE[THE COMPLETE CONCEPT IS TAKEN FROM THE CODE IN TEXT BOOK]
close all; clear all; randn('state',0) z=randn(2000, 1)+j*randn(2000, 1); Mg_z=sqrt(real(z).^2+imag(z).^2); width_of_PDF=1; Mag_square=Mg_z.^2; bincenters=[0.5:0.5:4]'; bins=length(bincenters); h=zeros(bins,1); for i=1:length(Mag_square) for k=1 :bins %close previously opened wndow %clear data in worksapce %initialize guassian random number generator %generate complex numbers %magnitude of complex numbers %probability density function's width %square of magnitude %specify bins center positions %total no of bins %generate 0's vector %assigning corresponding values to bins
if Mag_square(i)>bincenters(k)-0.5/2 & Mag_square(i)<=bincenters(k)+0.5/2 h(k,1)=h(k,1)+1; end end end pxest=h/(1000*0.5); xaxis=[0:0.01:5]'; px=0.5.*exp(0.5.*-xaxis); bar(bincenters,pxest,0.5) hold on plot(xaxis,px,'r') legend('estimated','true') grid; title(' PDF for the Magnitude Squared of z i.e. |z|^2' ); xlabel('complex #s.'); ylabel('Estimated and True Probability'); %true probability %estimated probability
GRAPH:
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.