Thursday, December 31, 2015

In this assignment we will use the function subplot(#rows,#columns,cell#) to compare the change in some distributions as there parameters change. subplot(#rows,#columns,cell#) creates multiple sub-fi gures within one g- ure. #rows tells the number of rows, #columns tells the number of columns, and cell# tells the sub- figure we are currently addressing

In this assignment we will use the function subplot(#rows,#columns,cell#)
to compare the change in some distributions as there parameters change.
subplot(#rows,#columns,cell#) creates multiple sub-fi gures within one g-
ure. #rows tells the number of rows, #columns tells the number of columns, and
cell# tells the sub- figure we are currently addressing.
For example:
vector X = [1:10];
subplot( 2,1,1 ), hist( vector X ), title( `Histogram' )
subplot( 2,1,2 ), bar( vector X ), title( `Bar Graph' )
Creates a 2 *1 figure.
  • (1) Recreate the bar graph of the PMF of the Geometric Distribution from assignment 3 for p = 0:15; 0:33; 0:5; 0:66; 0:85 in one gure using subplot(). (Either 2 3 or 3 2, with one cell empty.) Title each subplot with the value of p.


Live Code:
sum = 0;
geoV1 = 1:15;
p= 0;
for y = 0:5
    if y == 1
     p =0.15;
    end
     if y ==2
    p=0.33;
     end
     if y == 3
         p =0.5;
        
     end
     if y == 4
         p = 0.66;
     end
     if y == 5
         p=0.85;
     end
    
for x =1:15
    geo = ((1-p)^(x-1)) * p;
    geoV1(x)= geo;
    result = geoV1;
if y == 1
    a = geoV1;
end
if y==2
    b = geoV1;
end
if y ==3
    c = geoV1;
end

if y == 4
    d = geoV1;
end

if y ==5
   e = geoV1;
end
   
  %subplot(2,1,2), hist(geoV1), title('Histogram')
end
end
geoV1;
subplot(2,3,1),bar(a), title 'p =0.15'
subplot(2,3,2),bar(b), title 'p =0.33'
subplot(2,3,3),bar(c), title 'p =0.50'
subplot(2,3,4),bar(d), title 'p =0.66'
subplot(2,3,5),bar(e), title 'p =0.85'

  • (2) rand(1,n) generates a 1 n vector of Uniformly Distributed data. Plot a histogram of such vectors of length 20, 40, . . . 180 (9 in total) using subplot. Title each subplot with the sample size.

Live Code:
v1 = rand(1,20);
v2 = rand(1,40);
v3 = rand(1,60);
v4 = rand(1,80);
v5 = rand(1,100);
v6 = rand(1,120);
v7 = rand(1,140);
v8 = rand(1,160);
v9 = rand(1,180);

subplot(3,3,1),hist(v1), title 'Size = 20'
subplot(3,3,2),hist(v2), title 'Size = 40'
subplot(3,3,3),hist(v3), title 'Size = 60'
subplot(3,3,4),hist(v4), title 'Size = 80'
subplot(3,3,5),hist(v5), title 'Size = 100'
subplot(3,3,6),hist(v6), title 'Size = 120'
subplot(3,3,7),hist(v7), title 'Size = 140'
subplot(3,3,8),hist(v8), title 'Size = 160'
subplot(3,3,9),hist(v9), title 'Size = 180'

  • (3) randn(1,n) generates a 1 n vector of Normally Distributed data. Plot a histogram of such vectors of length 20, 40, . . . 180 (9 in total) using subplot. Title each subplot with the sample size.

Live Code :
subplot(3,3,1),hist(randn(1,20)), title 'Size = 20'
subplot(3,3,2),hist(randn(1,40)), title 'Size = 40'
subplot(3,3,3),hist(randn(1,60)), title 'Size = 60'
subplot(3,3,4),hist(randn(1,80)), title 'Size = 80'
subplot(3,3,5),hist(randn(1,100)), title 'Size =100'
subplot(3,3,6),hist(randn(1,120)), title 'Size = 120'
subplot(3,3,7),hist(randn(1,140)), title 'Size = 140'
subplot(3,3,8),hist(randn(1,160)), title 'Size = 160'
subplot(3,3,9),hist(randn(1,180)), title 'Size = 180'


 

No comments:

Post a Comment