Question

In: Statistics and Probability

I have the following assignment for probability class: I am supposed to write a routine (code)...

I have the following assignment for probability class:

I am supposed to write a routine (code) in MATLAB that does solve the following problem for me:

a) Generate N=10000 samples of a Uniform random variable (X) using the rand () command. This Uniform RV should have a range of -1 to +3.

b) Generate (Estimate) and plot the PDF of X from the samples.

You are not allowed to use the Histogram () command, any commands from the Matlab Statistics toolbox, or any routines from the companion textbook website!

c) Compute the expected value of X (average value) from the samples.

d) Generate (Estimate) and plot the CDF of X from the PDF in part b. e) Derive a new random variable Y using Y=X 2 f) Repeat steps b, c, d for the derived random Y.

Be sure to place appropriate axis labels and titles on your Matlab plots.

Solutions

Expert Solution

Matlab code with comments

Get this plot

get this

get these plot

Now do the above for

get these

the code in text format (tabs might not be retained)

clear;
%part a)
%set the number of samples
N=10000;
%uniform random between [a,b] is generated using a+(b-a)*rand()
a=-1;
b=3;
x=a+(b-a)*rand(N,1);
%part b) Estimate the pdf
%set the number of classes
breaks=20;
%set the class width
cw=ceil(range(x))/breaks;
%set the lower class interval of the first class as the minimum of x
lc=floor(min(x));
%get the frequency for each class
for i=1:breaks
freq(i)=length(find(x<lc+cw))-length(find(x<lc));
%store the mid point
mid(i)=lc+cw/2;
%increment the lc to the next class
lc=lc+cw;
end
% get the empirical pdf
epdf=freq/(N*cw);
%plot this
figure(1);
bar(mid,epdf);
title('PDF of X');
xlabel('X');
ylabel('Density');

%part c) Expected value
fprintf('Expected value of X is %.4f\n',mean(x));

%part d) generate the cdf
ecdf=cumsum(freq)/N;
%plot this
figure(2);
plot(mid,ecdf);
title('CDF of X');
xlabel('X');
ylabel('Cumulative Probability');

%repeat for Y=X2
%part a)
y=x.^2;
%part b) Estimate the pdf
%set the number of classes
breaks=20;
%set the class width
cw=ceil(range(y))/breaks;
%set the lower class interval of the first class as the minimum of x
lc=floor(min(y));
%get the frequency for each class
for i=1:breaks
freq(i)=length(find(y<lc+cw))-length(find(y<lc));
%store the mid point
mid(i)=lc+cw/2;
%increment the lc to the next class
lc=lc+cw;
end
% get the empirical pdf
epdf=freq/(N*cw);
%plot this
figure(3);
bar(mid,epdf);
title('PDF of Y');
xlabel('Y');
ylabel('Density');

%part c) Expected value
fprintf('Expected value of Y is %.4f\n',mean(y));

%part d) generate the cdf
ecdf=cumsum(freq)/N;
%plot this
figure(4);
plot(mid,ecdf);
title('CDF of Y');
xlabel('Y');
ylabel('Cumulative Probability');


Related Solutions

I have the following code for my java class assignment but i am having an issue...
I have the following code for my java class assignment but i am having an issue with this error i keep getting. On the following lines: return new Circle(color, radius); return new Rectangle(color, length, width); I am getting the following error for each line: "non-static variable this cannot be referenced from a static context" Here is the code I have: /* * ShapeDemo - simple inheritance hierarchy and dynamic binding. * * The Shape class must be compiled before the...
I'm getting an error with my code on my EvenDemo class. I am supposed to have...
I'm getting an error with my code on my EvenDemo class. I am supposed to have two classes, Event and Event Demo. Below is my code.  What is a better way for me to write this? //******************************************************** // Event Class code //******************************************************** package java1; import java.util.Scanner; public class Event {    public final static double lowerPricePerGuest = 32.00;    public final static double higherPricePerGuest = 35.00;    public final static int cutOffValue = 50;    public boolean largeEvent;    private String...
I am in a class where I am supposed to be Minister of Foreign Affair representing...
I am in a class where I am supposed to be Minister of Foreign Affair representing India. I was invited to the G20 meeting to discuss and present negotiations with other countries of G20. The agenda will have two major items: international health cooperation and international economic cooperation. What negotiations could I do for India with other countries to improve the current situation and look for financial stability?
I am in a class where I am supposed to be a Civil Society Organization Representative...
I am in a class where I am supposed to be a Civil Society Organization Representative (CSO) representing India. I was invited to the G20 meeting to discuss and present negotiations with other countries of G20.The agenda will have two major items: international health cooperation and international economic cooperation. What negotiations could I do for India with other countries to improve the current situation and look for financial stability?
Hi, I am working on this assignment where we have to read and write to a...
Hi, I am working on this assignment where we have to read and write to a file. Change any code that needs to be changed, I need the wfile and rfile functions to be edited to work and the rest of the program. please change the gets() to something that works. if I need to create a .txt file to run the program pls let me know Thanks in advance for the help //agalloc.c // maintains list of agents infile,...
For my math class I am required to write an essay on the following topic: Write...
For my math class I am required to write an essay on the following topic: Write an essay about the existence and uniqueness of a solution to an ODE( ordinary differential equation) ? I do not require that the essay be written but can you possibly give me some hints and extra information that I may include in my essay.
I have a code and it works and runs as it supposed too. What is the...
I have a code and it works and runs as it supposed too. What is the UML for it? Any help will be awesome. Thanks. import java.util.Scanner; public class StringToMorseCode { public static void main(String[] args){ Scanner input = new Scanner(System.in);    char[] letters = { ' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6',...
JAVA CODE BEGINNERS, I already have the demo code included Write a Bottle class. The Bottle...
JAVA CODE BEGINNERS, I already have the demo code included Write a Bottle class. The Bottle will have one private int that represents the countable value in the Bottle. Please use one of these names: cookies, marbles, M&Ms, pennies, nickels, dimes or pebbles. The class has these 14 methods: read()(please use a while loop to prompt for an acceptable value), set(int), set(Bottle), get(), (returns the value stored in Bottle), add(Bottle), subtract(Bottle), multiply(Bottle), divide(Bottle), add(int), subtract(int), multiply(int), divide(int), equals(Bottle), and toString()(toString()...
Scenario: I am creating a course for inclusion into an established nursing curriculum. I am supposed...
Scenario: I am creating a course for inclusion into an established nursing curriculum. I am supposed to describe the program level of the course am proposing. What do they mean by program level? This is a hypothetical community college with a two year nursing program.
I am trying to write a code in C for a circuit board reads in a...
I am trying to write a code in C for a circuit board reads in a temperature from a sensor on the circuit board and reads it onto a 7-segment LED display. How exactly would you code a floating 2 or 3 digit reading onto the LED display? I am stuck on this part.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT