%% Plot Inverse of Lower Incomplete Gamma Function
% Calculate the inverse of the lower incomplete gamma function for a = 0.5, 1, 1.5, and 2 within the interval 0\leq y \leq 1. Loop over values of a, evaluate the inverse function at each one, and assign each result to a column of X.

A = [0.5 1 1.5 2];
Y = 0:0.005:1;
X = zeros(201,4);
for i = 1:4
    X(:,i) = gammaincinv(Y,A(i));
end

% Plot all of the inverse functions in the same figure.

plot(Y,X)
grid on
legend('$a = 0.5$','$a = 1$','$a = 1.5$','$a = 2$','interpreter','latex')
title('Lower inverse incomplete gamma function for $a = 0.5, 1, 1.5,$ and $2$','interpreter','latex')
xlabel('$y$','interpreter','latex')
ylabel('$P^{-1}(y,a)$','interpreter','latex')

% Copyright 2019 The MathWorks, Inc.