How do I plot the function: p(d) = (2d/t) exp(−d^2/t) in matlab. I am using hold on, to plot this probability distribution function along with a histogram (code shown below).
for i = 1:5000
[x, y] = RandomWalkFunction(300);
distance100(i) = sqrt(x(101)^2+y(101)^2); % cumsum at t = 100
distance200(i) = sqrt(x(201)^2+y(201)^2); % cumsum at t = 200
distance300(i) = sqrt(x(301)^2+y(301)^2); % cumsum at t = 300
end
figure(i)
% plot the walks
subplot(3,1,1)
hist(distance100,1:2:50,'BinLimits',[0 50])
title('t = 100')
xlabel('Distance from Origin')
ylabel('Relative Frequency')
ylim([0 1500])
xlim([0 60])
hold on
%p(d) = (2d/t) exp(?d^2/t)
hold off
for any help, please do comment.
CODE:
for i = 1:5000
[x, y] = RandomWalkFunction(300);
distance100(i) = sqrt(x(101)^2+y(101)^2); % cumsum at t = 100
distance200(i) = sqrt(x(201)^2+y(201)^2); % cumsum at t = 200
distance300(i) = sqrt(x(301)^2+y(301)^2); % cumsum at t = 300
end
figure,hold on
% plot the walks in 1st subplot
subplot(1,2,1)
hist(distance100,1:2:50,'BinLimits',[0 50])
title('t = 100')
xlabel('Distance from Origin')
ylabel('Relative Frequency')
ylim([0 1500])
xlim([0 60])
% plot the walks in 2nd subplot
p=(2*d./t).*exp(-d.^2./t);
subplot(1,2,2)
plot(t,p)
xlabel('value t')
ylabel('probabilty distributive function')
hold off
Get Answers For Free
Most questions answered within 1 hours.