如何计算伽马分布中的中位数?

How can I calculate the median in a gamma distribution?

我有以下分布,我想计算它的中位数:

x=0:0.01:10;
x=[x' x' x' x' x'];
a=ones(1,1001)';
a=[a*2 a*4 a*6 a*8 a*10];
b=2;
f = gampdf(x,a,b);
plot(x,f)
grid on

用户 TwistedSim 回答了我的问题。

You need to find the value m for which the integral from 0 to m give you 0.5. You can do that with c = cumsum(f)*dx where dx = 0.01 in your case. After it's just a matter of using find(c>0.5, 1, 'first').

dx = 0.04;
b=2;

x=kron([0:dx:10]',ones(1,5));
a=kron(ones(size(x,1),1),[2:2:10]);
f = gampdf(x,a,b);
cf = cumsum(f)*dx;
[i,j] = find(cf(1:end-1,:)<0.5 & cf(2:end,:)>=0.5);

cflow  = cf(sub2ind(size(x),i  ,j));
cfhigh = cf(sub2ind(size(x),i+1,j));

xm = x(i)+dx/2 + (0.5-cflow)./(cfhigh-cflow) * dx
fm = gampdf(xm',a(1,:),b)';

plot(x,f)
hold on; plot([xm xm]',[fm fm]','*'); hold off
grid on