0

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)]);
4

1 回答 1

1

Your ymaxis 100*sin(pi)which is0与 相同ymin。所以你的第二个直方图分箱不正确。我已经解决了这个问题,以及您代码中的其他一些问题。

但它不起作用的原因是另一个问题。您通过将函数应用于角度的预期来计算距离的预期值。这是不正确的,因为函数不是线性的,因此63.65(大约)正确的期望值(即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)]);
于 2014-10-13T03:36:56.537 回答