%% Plot Scaled Incomplete Gamma Function
% Calculate the unscaled lower incomplete gamma function and compare it to the scaled function.
% Calculate the unscaled lower incomplete gamma function for a = 1 within the interval 0\leq x\leq 2. Plot the function.

a = 1;
x = 0:0.001:2;
Y = gammainc(x,a);
plot(x,Y);
xlabel('$x$','interpreter','latex');
ylabel('$P(x,1)$','interpreter','latex')
hold on

% Next, calculate the scaled lower incomplete gamma function. Plot the function on the same graph. The scaled function has different asymptotic behavior near 0, which avoids underflow when x is close to 0.

Ys = gammainc(x,a,'scaledlower');
plot(x,Ys,'--');
legend('unscaled','scaled')

%
% Copyright 2019 The MathWorks, Inc.