%
% s05probability.m - Compute the median of a Chi^2(4),
% f(x)=(x/4)exp(-x/2)
% median=3.3567
% f(med)=0.1567
%
format short;
med=fzero(@(x)(x*exp(-x/2)+2*exp(-x/2)-1),4.0); % med=3.3567;
ymed=med/4*exp(-med/2); %ymed=0.1567;
X=0:0.1:10;
Y=X.*exp(-X/2)/4;
X1=zeros(17)+med;
Y1=0:0.01:0.16;
h=plot(X,Y,'b-',X1,Y1,'m-',[3.3567],[0.1567],'r.');
text(3.3567,0.01,'median=3.3567')
set(h,'MarkerSize',13)
title('\chi^2(4): f(x)=(x/4)e^{-x/2}, x>=0')