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'


 

Plot a sphere, which is parametrically de ned as [x(t; s); y(t; s); z(t; s)] = [cos(t) cos(s); cos(t) sin(s); sin(t)] for t; s = [0; 2 ] (use surf).

Plot a sphere, which is parametrically de ned as [x(t; s); y(t; s); z(t; s)] =
[cos(t) cos(s); cos(t) sin(s); sin(t)] for t; s = [0; 2 ] (use surf).





Plot a funnel shaped spiral in 3D: [x; y; z] = [t sin(t); t cos(t); t] for t = [0; 10]. (Use plot3) Use an appropriate sampling to get smooth curves.

  • (4) Plot a funnel shaped spiral in 3D: [x; y; z] = [t sin(t); t cos(t); t] for t = [0; 10]. (Use plot3) Use an appropriate sampling to get smooth curves.

Plot the functions f(x) = x; g(x) = x3; h(x) = ex and z(x) = ex2over the interval [0; 4]. Use an appropriate sampling to get smooth curves. Describe your plots by using the functions: xlabel,ylabel,title.

  • (3) Plot the functions f(x) = x; g(x) = x3; h(x) = ex and z(x) = ex2over the interval [0; 4]. Use an appropriate sampling to get smooth curves. Describe your plots by using the functions: xlabel,ylabel,title.

 

Plot a circle with the radius r = 2, knowing that the parametric equation of a circle is [x(t); y(t)] = [rcos(t); rsin(t)] for t = [0; 2]

  • (2) Plot a circle with the radius r = 2, knowing that the parametric equation of a circle is [x(t); y(t)] = [rcos(t); rsin(t)] for t = [0; 2]


Make a plot connecting the coordinates: (2; 6); (2:5; 18); (5; 17:5); (4:2; 12:5) and (2; 12) by a line.

  • (1) Make a plot connecting the coordinates: (2; 6); (2:5; 18); (5; 17:5); (4:2; 12:5) and (2; 12) by a line.
    • Matlab code 




Wednesday, December 30, 2015

For this assignment you will plot the probability mass function and the cumula- tive distribution function of the binomial distribution an geometric distribution



Instructions
  • For assignment 2 we generated the pmf of the Binomial Distribution (recall: f(x) = (n choose x)( p^(x) ) *  (1 - p) (n - x) for x = 0; 1; 2; : : : ; 10, [in Matlab terms: f(x) = nchoosek( n, x ) * p^x * (1-p)^(n-x) ]).
  • For this assignment you will plot the probability mass function and the cumula-tive distribution function of the binomial distribution for p = 0:15; 0:33; 0:5; 0:66; 0:85 and n = 10. How does the shape change as a function of p?
  • The pmf of the Geometric Distribution is given as : f(x) = ((1- p)^(x-1 ))p [in Matlab: (1-p)^(x-1) * p], for x = 1; 2; : : :. Plot the probability mass function and the cumulative distribution function of a geometric distribution with p = 0:15; 0:33; 0:5; 0:66; 0:85 for x = 1; 2; : : : ; 15. How does the shape change as a function of p?
 Binomial Distribution
  • Binomial Probability Cumulative Distribution
1p =0.15

2p = 0.33

3p = 0.5

4p = 0.66

5p = 0.85
  • Binomial Probability Mass Function
1p = 0.15
2p =0.33

3p = 0.5

4p =0.66

  
Geometric Distribution 
  • Probability Cumulative function 





    • Probability Mass Function