0
votes

I have a question about using MATLAB to find the probability density function. The question is about the range of a cannon projectile with gravity, g = 9.8 m/s, and velocity, v = sqrt(980) m/s. The angle, theta, is a uniformly distributed random variable between 0 and pi/2. I have to plot the uniform distribution of theta and the probability density function of the range fr(r) using the function of a random variable and the mean distance of the projectile.

So far, I have used the equation from physics, r = V^2*sin(2*theta)/g, to figure out the mean and sigma. sigmatheta = (pi/2)/sqrt(12) and meantheta = pi/2/2 Simplifying the equation, r = 100*sin(2*theta). I know the uniform distribution, ftheta(theta) goes from 0 to pi/2 and equal to 2/pi, .6366. The following code was given as an example for uniform and probability density function plotting. I have replaced the numbers I saw fit pertaining to this specific question. Using the formula, g(meantheta) + sigmatheta^2/2 *(g''(meantheta)), the mean of r should be 58.87, but the plot shows 63.65, so I already see there may be some errors in the code or my understanding of the problem. fr(r) is the probability density plot for the range of the projectile.

The uniform distribution plots correctly, but I seem to have an error with the probability density function. I was wondering if I could get some help fixing it.

p.s. Sorry for the long background information thank you!

samp_num=1000000;
xmin =0;                    %xmin for uniform distribution, a x is theta
xmax=pi/2;                  %xmax for uniform distribution, b
deltx=xmax-xmin;            %difference between xmax,xmin, pi/2, b-a
x=xmin+((deltx)*rand(1,samp_num));%numbers between 0 and pi/2
y=(100*sin(2.*x));          %g(x)=y=100*sin(2*x) y is range
ymax=(100*sin(2.*xmax));    %g(pi/2), g(b)
ymin=(100*sin(2.*xmin));    %g(0), g(a)
delty=ymax-ymin;            %g(b)-g(a)
mean_x=mean(x);             %ux
std_x=std(x);               %sigmax
mean_y=mean(y);             %uy
std_y=std(y);
bin_sizex=deltx/100;
binsx=[xmin:bin_sizex:xmax];
u=hist(x,binsx);
u1=u/samp_num/bin_sizex;
bin_sizey=delty/100;
binsy=[ymin:bin_sizey:ymax];
v=hist(y,binsy);
v1=v/samp_num/bin_sizey;
sum_v1=sum(v1)*bin_sizey;
subplot(2,1,1)
bar(binsx,u1)
legend(['mean=',num2str(mean_x),'std=',num2str(std_x)]);
subplot(2,1,2)
bar(binsy,v1)
legend(['mean=',num2str(mean_y),' std=',num2str(std_y)]);
1

1 Answers

1
votes

Your ymax is 100*sin(pi) which is 0, same as ymin. So your second histogram is binning incorrectly. I've fixed that, and a few other things in your code.

But the reason that it's not working is a different issue. You are calculating the expected value of distance by applying your function to the expected of the angle. This is not correct because the function is not linear, so 63.65 is (approximately) the correct expected value (which is 200/pi=65.66...).

samp_num=1000000;
N=100
xmin=0;                     %xmin for uniform distribution, a x is theta
xmax=pi/2;                  %xmax for uniform distribution, b
deltx=xmax-xmin;            %difference between xmax,xmin, pi/2, b-a
x=xmin+(deltx)*rand(1,samp_num);%numbers between 0 and pi/2
y=100*sin(2.*x);            %g(x)=y=100*sin(2*x) y is range
ymax=max(y);                %g(pi/2), g(b)
ymin=min(y);                %g(0), g(a)
delty=ymax-ymin;            %g(b)-g(a)
mean_x=mean(x);             %ux
std_x=std(x);               %sigmax
mean_y=mean(y);             %uy
std_y=std(y);
[u,binsx]=hist(x,N);
u1=u/samp_num/(deltx/(N));
[v,binsy]=hist(y,N);
v1=v/samp_num/(delty/(N));
subplot(2,1,1)
bar(binsx,u1)
legend(['mean=',num2str(mean_x),'std=',num2str(std_x)]);
subplot(2,1,2)
bar(binsy,v1)
legend(['mean=',num2str(mean_y),' std=',num2str(std_y)]);