Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(a) The Matlab rand() function generates samples of a continuous random variable

ID: 2990403 • Letter: #

Question

(a) The Matlab rand() function generates samples of a continuous random variable which is uniformly distributed between 0 and 1. The fragment of Matlab code x = rand(1000,1); a = ; b = ; y = a*x + b; is intended to generate samples of a random variable Y with a PDF shown below. Determine the appropriate values for a and b. (b) Verify that these values are correct by plotting the histogram of y. Note: the histogram may not be perfectly flat because we have a finite number of samples. (c) Starting with the fragment in (a), write a small Matlab script that will compute P(2

Explanation / Answer

y=a*x+b => -1 = a*0+b there fore b=-1

4= a*1+b => 5 =a

(b)

a=5;
b=-1;
rand(1000,1);
y= a*x+b;

hist(y);

(c)

%%MATLAB Script %%

%save and run this in a m file%

a=5;
b=-1;
x=rand(1000,1);
y= a*x+b;
count = sum( y(:)>3 & y(:)<6 );
prob= count/1000