Professional Documents
Culture Documents
ASSIGNMENT
1) Write a MATLAB code to produce a randomly generated number that is equally likely to
produce any number from set {0,1,2,.....,9}. Answer:% Digital Communication Assignment Question No:-1 clear all; close all; r=randint(1,1,10); r
2) Write a MATLAB code to produce a randomly generated number that follows Bernoulli
distribution for an arbitrary parameter p. Answer:% Digital Communication Assignment, Question No:-2 clear all; close all; p=input('Enter the probability of success '); if p<=1 b=binopdf(1,1,p); b else disp('Entered value is wrong'); end Output:Enter the probability of success .5 b = 0.5000
4) Write and execute a MATLAB program to calculate n! For an arbitrary n. Using that
program calculate 64! Answer:% Digital Communication Assignment Question No:-4 clear all; close all; f=1; n=input('Enter the value of n, of which factorial is to be found '); if (n>0) for i=1:n; f=f*i; end; disp('Factorial is, '); f else
5) Draw a histogram of random numbers, along with a Gaussian PDF , where = 5 and
= 2. Answer:% Digital Communication Assignment Question No:- 5 clear all; close all; x=1:10; g=normpdf(x,5,2); disp('Mean is 5 and SD is 2'); stem(x,g); Output:Mean is 5 and SD is 2
3
2.5
1.5
0.5
0 -0.15
-0.1
-0.05
0.05
0.1
0.15
0.2
0.25
0.3
0.35
7) Use the MATLAB rand function to create a random variable (k), uniformly distributed
over (0,1). Then create a new random variable according to y =-ln(x). Repeat this procedure many times to create a large number of realizations of y.Using these samples, estimate and plot PDF of y. Answer:%Digital communication Assignment Question No:- 7 clear all; close all; k=rand(1,10); y=-log(k); z=normpdf(y,2,4); stem(1:10,z); Output:-
0.1 0.09 0.08 0.07 0.06 0.05 0.04 0.03 0.02 0.01 0
10
b=input('Enter the value of b, b > 0 '); u=input('Enter the mean '); var=input('Enter the variance '); sig=sqrt(var); x=abs(a+b); if (a>0 && b>0) p=normcdf(x,u,sig); disp('P(|x-a|<b) is '); p else disp('Entered value is incorrect '); end Output:Enter the value of a, a > 0 3 Enter the value of b, b > 0 4 Enter the mean 5 Enter the variance 2 P(|x-a|<b) is p = 0.9214