The r.v. x has the half sinewave pdf shown. a) Evaluate and plot in MATLAB the c
ID: 2248044 • Letter: T
Question
The r.v. x has the half sinewave pdf shown.
a) Evaluate and plot in MATLAB the cdf for x.
b) You are going to generate the r.v. x in MATLAB using only the uniform random function rand. Derive a relationship between x and the uniform r.v. u in the interval [0,1).
c) Generate a row vector in MATLAB consisting of one million samples of x using the uniform generator rand and your equation in part b. You are going to estimate the pdf for x using a histogram on the generated data.
>> [B,T]=hist(x,31);
Hint: The function hist will auto=range the one million samples of x into 31 equally spaced bins and return the number of samples in each bin in the row vector B. The row vector, T, is the location of the bin centers along the x-axis.
d) Using the data B and T in part c, create a bar graph estimate of the pdf for x and compare this graph with the given pdf graph for this problem.
Warning: while B divided by one million is an estimate for the probability of finding x in the various bins, this is not quite the same thing as the pdf.
pdfx = (pi/2).sin(pi.x) 6 1.4 1.2 0.8 0.6 0.4 02 0 0.1 02 03 0.4 0.5 0.6 0.7 0.8 0.9Explanation / Answer
a)instead of the usual definition cdf(x) = Prob(X <= x) .The best symmetric definition cdf(x) = Prob(X < x) + 1/2 * Prob(X == x) , which is more suitable to cases with ties. Now the computation is a one-liner, but with the help of the tiedrank() function from the statistical toolbox:
For example,
yields
==============================================================================
b)uniform random function rand
samp_num=1000000;
N=100
xmin=0; %xmin for uniform distribution, a x is theta
xmax=pi/2; %xmax for uniform distribution, b
deltx=xmax-xmin; %difference between xmax,xmin, pi/2, b-a
x=xmin+(deltx)*rand(1,samp_num);%numbers between 0 and pi/2
y=100*sin(2.*x); %g(x)=y=100*sin(2*x) y is range
ymax=max(y); %g(pi/2), g(b)
ymin=min(y); %g(0), g(a)
delty=ymax-ymin; %g(b)-g(a)
mean_x=mean(x); %ux
std_x=std(x); %sigmax
mean_y=mean(y); %uy
std_y=std(y);
[u,binsx]=hist(x,N);
u1=u/samp_num/(deltx/(N));
[v,binsy]=hist(y,N);
v1=v/samp_num/(delty/(N));
subplot(2,1,1)
bar(binsx,u1)
legend(['mean=',num2str(mean_x),'std=',num2str(std_x)]);
subplot(2,1,2)
bar(binsy,v1)
legend(['mean=',num2str(mean_y),' std=',num2str(std_y)]);
======================================================================
c)
To use 10,000 values between 0 and 10 to calculate each element of z, and you are going to calculate one million random numbers in total, then I think this is what you want:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.