0001
0002
0003
0004
0005
0006
0007
0008 close all
0009
0010 addpath(genpath('../General-Functions/'));
0011
0012
0013
0014 ss = plot_init;
0015
0016
0017
0018 init_rand_seed(2);
0019
0020
0021
0022
0023 N = 225;
0024 mu_y = 2;
0025 sigma_y = 0.25;
0026
0027
0028
0029
0030 x = randn(N,1);
0031
0032 y = mu_y*ones(N,1)+sigma_y*x;
0033
0034
0035 figure('name','Sample','color','w','Position',[0.1*ss(1),0.55*ss(2),0.35*ss(1),0.35*ss(2)]); hold on
0036 for n=1:N
0037 plot([y(n),y(n)],[0,0.5],'-k','LineWidth',1)
0038 end
0039 plot([mu_y-4*sigma_y,mu_y+4*sigma_y],[0,0],'-k','LineWidth',1);
0040 plot([0,0],[0,1],'-k','LineWidth',1);
0041 xlim([mu_y-5*sigma_y,mu_y+5*sigma_y]); ylim([-0.1,1.1]);
0042 xlabel('$y$');
0043
0044 title(['Fig. 2.11a A sample of $N = ',num2str(N),'$ normally distributed random variables $y\sim N('...
0045 ,num2str(mu_y),',',num2str(sigma_y),')$'])
0046
0047
0048 figure('name','Histogram','color','w','Position',[0.55*ss(1),0.55*ss(2),0.35*ss(1),0.35*ss(2)]); hold on;
0049
0050 N_bin = floor(sqrt(N));
0051 [NN,r]=hist(y,N_bin);
0052 bar(r,NN)
0053
0054
0055 range = abs(r(N_bin)-r(1))*N_bin/(N_bin-1);
0056 plot(r,N_bin*range*normpdf(r,mu_y,sigma_y),'-r','LineWidth',4);
0057 xlim([mu_y-5*sigma_y,mu_y+5*sigma_y]);ylim([0,max(NN)*1.1]);
0058 xlabel('$y$');ylabel('$\sim p_y(y)$')
0059 title(['Fig. 2.11b Histogram of the sample with $',num2str(N_bin),'$ bins, overlayed with its probability density.'])
0060
0061
0062
0063
0064 sigma_x = 4.9;
0065 sigma_y = 3.2;
0066 rho = 0.7;
0067 N = 500;
0068
0069
0070 C = [sigma_x^2 sigma_x*sigma_y*rho; sigma_x*sigma_y*rho sigma_y^2];
0071
0072 x = rand_gauss([0,0]',C,N)';
0073
0074
0075 figure('name','2D Sample','color','w','Position',[0.25*ss(1),0.1*ss(2),0.35*ss(1),0.35*ss(2)]); hold on
0076
0077 plot_ellipse(struct('mean',[0;0],'cov',C),'-k');
0078
0079 plot_ellipse(struct('mean',[0;0],'cov',9*C),'-g');
0080
0081 plot([-4*sigma_x,+4*sigma_x],[0,0],'-k')
0082
0083 plot([0,0],[-4*sigma_y,+4*sigma_y],'-k')
0084
0085 plot(x(:,1),x(:,2),'.k')
0086
0087 xlim([-5*sigma_x,+5*sigma_x]);ylim([-5*sigma_y,+5*sigma_y])
0088 axis equal
0089 title({'Fig. 2.11c Sample of 2d random vector','standard ellipse (black), threefold standard ellipse (green)'})