a) Create an array x of uniform random numbers by using the command x=rand(10000
ID: 2080499 • Letter: A
Question
a) Create an array x of uniform random numbers by using the command x=rand(100000,1)
b) Plot a histogram of x using the command hist(x,100). This will create a histogram with
100 bins and with arbitrary scaling. Make a comment about the probability of being in
each of the bins. Calculate the mean value of x and the standard deviation.
c) Create an array y using the command y=randn(100000,1).
d) Plot a histogram of y using the command hist(y,100). Make observations on the
difference between the distribution of values for x and for y.
e) Calculate the mean and standard deviation of y.
f) Write a program to figure out the probability of a point in the y array is >1.0. There are a
number of ways to do it.
Explanation / Answer
clc;
clear all;
close all;
% QUESTION a)
x = rand(100000,1)
% QUESTION b)
histx = hist(x,100)
figure
plot(histx);
M1 = mean(x)
SD1 = std(x)
%FOR A SINGLE SAMPLE, THE PROBABILITY WILL BE 1/(B-A) = 1/(1-0) = 1
%BUT FOR 100 BINS, IT WILL BE EQUALLY DISTRIBUTED AS 1/100 = 0.01
% QUESTION c)
y = randn(100000,1)
% QUESTION d)
histy = hist(y,100)
figure
plot(histy);
%THE GRAPH OF histy IS AS PER THE NORMAL DISTRIBUTION WHEREAS histx IS
%RANDOM.
% QUESTION e)
M2 = mean(y)
SD2 = std(y)
%QUESTION f)
%IMPLEMENTING STANDARD NORMAL DISTRIBUTION PDF
fx = @(x) (1/((2*pi).^0.5)).*exp(-x.^2); %AS randn function is normal
%distribution with mean = 0 and standard deviation = 1, which is nothing
%but standard normal distribution
%PROBABILITY OF X > 1.0
PX = integral(fx,1.0,Inf)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.