matlabgamma-distribution

How can I calculate the median in a gamma distribution?


I have the below distribution, which I want to calculate the median of:

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

Visualization of Distribution


Solution

  • User TwistedSim answered my question.

    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').