Hi, I wanted to get a quick look over for my program see if there were any flaws.. I think it's complete. specifications and program in link thanks..
1 view (last 30 days)
Show older comments
I think the only thing i'm missing is the mean of the means (not very difficult but I am feeling lazy after working on this all day)
and the histogram displaying correctly at the moment I'm not sure it would display with the randomly generated values I think it should be simple to input I'm just new to MATLAB.. Thank you :)
Specifications for program below:
1. Generate 100 samples of size 225 random numbers from U(-3,6). For each of these 100 samples calculate the mean.
a) Find the simulated probability that the mean is between 1 and 2.
b) Find the mean of the means.
c) Find the standard deviation of the means.
d) Draw the histogram of the means.
nsamples=100;
samplenum = 1:nsamples;
%setting number of samples and the sample amt. i.e. here there
%is only 1 sample of number 100
n = 225;
%sample size 225
a = 1;
%setting first mean value of 1
b = 2;
%setting second mean value of 2
theProbability = sum(nsamples > a & nsamples < b) / n;
%finding the probability that the mean is between a and b
a + (b-a)*rand()
%gives uniform random values in the interval [a,b]
data = a + (b-a)*rand(1, nsamples);
%setting data values
cMean = mean(data)
%calculating mean of data
cStdDev = std(data)
%calculating standard deviation of data
z = normrnd(-3,6,n,1);
%setting distribution of random numbers U(-3,6) (n)=(U) here
hist(z,-9.75:.5:9.75);
%setting histogram values for x-axis (labeled here as z)
xlim([-10 10]);
%setting x-axis coordinates
title('Generating 100 Samples of Size 225 Simulated U(-3,6) Random Numbers Histogram Question 1 Part d)');
%title of histogram
xlabel('Z');
%labeling x-axis
ylabel('Frequency');
%labeling y-axis
0 Comments
Accepted Answer
Alexandra Harkai
on 29 Nov 2016
The random sample comes from a normal instead of a uniform sample (assuming U stands for uniform). Also all the data you generated is in the (a,b) interval which will give you 1 for question a).
nsamples=100; % number of samples
n = 225; % sample size 225
a = 1;
b = 2;
data = -3+9*rand(nsamples, n); % random 100x225 data sample from a uniform (0,1) distribution
cMean = mean(data, 2); % mean of each sample
answer_a = sum(cMean > a & cMean < b)/nsamples; % how many data means are between a and b
answer_b = mean(cMean);
answer_c = std(cMean, 1);
hist(cMean);
title('Generating 100 Samples of Size 225 Simulated U(-3,6) Random Numbers Histogram Question 1 Part d)'); %title of histogram
xlabel('Z'); %labeling x-axis
ylabel('Frequency'); %labeling y-axis
3 Comments
Alexandra Harkai
on 29 Nov 2016
Np. Hope it explains itself and helps to see where the first version did something funky.
More Answers (0)
See Also
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!