see the attached file, i need this assignment donw in 24 hrs
SURE 372 – Adjustment Comp.
Winter/Fall 2013
Homework No. 2.
Histograms
Objectives:
1. Use of histograms to show data.
Introduction:
Histograms allow the visual representation of datasets. These are used to obtain an idea of the distribution of the
dataset.
Task1:
Compute and plot the path(s) of a set of random particles that are confined by a pair of barriers at +B units and -B
units from the origin (where the particles all start from).
A random path is computed by repeatedly performing the calculation
xj+1 = xj + s
where s is a number drawn from the random number generator (rand in MATLAB).
For example, a path would be handled by the code fragment
x(1) = 0;
y(1) = 0;
z(1) = 0;
while ((abs(x(j))<(B)) && (abs(y(j))<(B)) && (abs(z(j))<(B))); x(j+1) = x(j) + rand;
y(j+1) = y(j) + rand;
z(j+1) = z(j) + rand;
end
where j is the number of steps needed to reach barrier B.
What do you do with all the paths that you generate? Compute statistics, of course. Answering questions like
What is the average position of the particles as a function of time? What is the standard deviation of the position of
the particles as a function of time?
Set B=5.
Calculate mean and standard deviation for 100, 1000, 5000, 10 000 and 30 000 paths for number of steps. Plot
histogram of steps with hist command. Find the average of steps with the mean command. Find standard deviation
with std command. How does the average and std of the number of steps change with respect to the number of paths
run? How does the histogram change? Answer these as comments in the program. Take a look at a path with the
plot3 command.
Task2:
Compute and plot the average of N rolls of dice. Use the randperm(6) command to simulate a roll of dice. N rolls of
dice would be simulated by this fragment:
a=randperm(6);
d(1)=da(1);
2
s(1)=d(1);
for n=1:N
a=randperm(6);
d(n+1)=d(n)+a(1);
s(n+1)=d(n+1)/n;
end
where s is the average after each roll.
Calculate mean and standard deviation for 1, 10, 100, 1000, 10 000 and 100 000 rolls. Plot histogram of s with hist
command. Find the average of s with the mean command. Find standard deviation with std command. How does the
average and std change with the number of rolls? How does the histogram change? Answer these as comments in the
program.
Hand in:
Your matlab implementation through blackboard. Please put your name in program as a comment. Zip it if using
multiple files.