Question

How do I plot the function: p(d) = (2d/t) exp(−d^2/t) in matlab. I am using hold...

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

Homework Answers

Answer #1

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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
I am using matlab and getting a "matrix dimensions error below" for line 22. Can someone...
I am using matlab and getting a "matrix dimensions error below" for line 22. Can someone spot the error and try the code to fix the error. %The beginning step is to generate a functionf(t) that consists of the sum %of the following components % 25 Hz cosine function of magnitude 1 % 50 Hz sine function of magnitude 1 % 40 Hz square wave function of magnitude 1 clear; clc; close all; %sample rate is given at 2500 Hz...
Write a MATLAB m file to plot the 3-D curve represented by a multivariable function z(x,y)...
Write a MATLAB m file to plot the 3-D curve represented by a multivariable function z(x,y) = x2 −0.5y2 over x ∈ [−2,2] and y ∈ [−2,2]. Use a 2 point thickness. For both x an y axes, choose the grid size to be 0.05. Clearly label and title your plot. Rotate the view at an azymuth of −20 , and elevation of 20 . You need to use the following commands: x=-2:0.05:2; y=x; z=x.^2-0.5*y.^2; plot3(x,y,z,’LineWidth’,2) label(’ My 3D curve’);...
Given the function y = e-0.4(x-3)^2. Compute the corresponding values of yh. Use the bar(xh,yh,.3) command...
Given the function y = e-0.4(x-3)^2. Compute the corresponding values of yh. Use the bar(xh,yh,.3) command to produce a bar graph. Next superimpose a continuous bell curve over it by taking one thousand samples of a new variable x again from 0 to 6 with the step size 6/999. Issue the hold on command and then use plot(x,y,’r’,’LineWidth’,2) command. All these commands are listed below. clear all; close all ; clc xh = 0:6/9:6; yh = exp(-0.4*(xh-3).^2); bar(xh,yh,0.3); hold on...
Using the following code: % Ex 6.4 First-order step and impulse response for two time constants...
Using the following code: % Ex 6.4 First-order step and impulse response for two time constants % clear all; close all; t = 0:.1:100; % Time vector subplot(1,2,1); x = 250*exp(-0.05*t); plot(t,x,'k'); xlabel('Time (hrs)','FontSize',14); ylabel('P_A (mmHg)','FontSize',14); title('Impulse Response','FontSize',14); subplot(1,2,2); x = 20*(1-exp(-0.05*t)); plot(t,x,'k'); xlabel('Time (hrs)','FontSize',14); ylabel('P_A (mmHg)','FontSize',14); title('Step Response','FontSize',14);    ANSWER: The response of a 1st order linear body fluid balance system to step function (L m (t) = 1/s, Eqn. 6.9/p226) and impulse function (L d (t) = 1,...
PLEASE USE MAT LAB ONLY. THANK YOU (a) Create and plot the signals listed below and...
PLEASE USE MAT LAB ONLY. THANK YOU (a) Create and plot the signals listed below and save your Matlab code in a script file. i) Cosine signal of frequency 100 Hz over the range [0,0.1] seconds and samples spaced 10^- 4 seconds apart with a phase of pi/2 and an amplitude of 1.   PLEASE USE MAT LAB ONLY. THANK YOU ii) A square wave that oscillates between 0 and 1 every five samples, plot 3 periods of the waveform. iii)...
MATLAB Task 4: Plotting the trajectory of a ball thrown Write a user-defined function named throwBallFunc:...
MATLAB Task 4: Plotting the trajectory of a ball thrown Write a user-defined function named throwBallFunc: Which takes two arguments (parameters): Velocity and Angle Inside of the function, define some values (you can pick your own variable names) • Initial height of ball at release = 1.5m • Gravitational acceleration = 9.8m/s2 Next, create a time vector t that has 10000 values between 0 and 20, inclusive. The values must be sequential and not random If x is the vector...
Poisson Distribution: p(x, λ)  =   λx  exp(-λ) /x!  ,  x = 0, 1, 2, ….. Find the moment generating function Mx(t)...
Poisson Distribution: p(x, λ)  =   λx  exp(-λ) /x!  ,  x = 0, 1, 2, ….. Find the moment generating function Mx(t) Find E(X) using the moment generating function 2. If X1 , X2 , X3  are independent and have means 4, 9, and 3, and variencesn3, 7, and 5. Given that Y = 2X1  -  3X2  + 4X3. find the mean of Y variance of  Y. 3. A safety engineer claims that 2 in 12 automobile accidents are due to driver fatigue. Using the formula for Binomial Distribution find the...
Curve-Fit Function USING MATLAB Using the top-down design approach, develop a MATLAB function A8P2RAlastname.m that reads...
Curve-Fit Function USING MATLAB Using the top-down design approach, develop a MATLAB function A8P2RAlastname.m that reads data from a file and performs regression analysis using polyfit and polyval. The function shall have the following features: The input arguments shall include the file name (string), a vector of integers for the degrees of polynomial fits to be determined, and an optional plot type specifier (‘m’ for multiple plots, ‘s’ for a single plot - default). The data files will be text...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT