SUMPDF Probability distribution of the sum of distributions
[S,P,C]=SUMPDF(X1,P1,N1,X2,P2,N2,...) will return the distribution of the sum of distribution P1, at values at X1, N1 times plus the distribution P2, at values in X2, N2 times...
The output vectors, S, P, and C, are respectively the list of unique outcomes, probability of yielding that outcome, and the total number of ways of obtaining that outcome among all combinations.
Distribution of the total value when choosing 10 values from distribution (A) and 7 values from distribution (B).
X1=[-1 0 2]; P1=[.1 .2 .7]; N1=10; %(A)
X2=[ 0 1 2]; P2=[.3 .5 .2]; N2=7; %(B)
subplot(2,1,1), plot(S,P), grid on
title('Probability distribution of total value')
subplot(2,1,2), plot(S,C), grid on
title('Number of combinations possible to obtain each outcome')
This illustrates that while an outcome of 10 has the most combinations of ways to happen, it is actually a total of 20 which is the most likely to happen due to the given probabilities of values.
Note: Program assumes discrete distribution. If using continuous distributions, and using densities as inputs, a normalization must be made afterwards. Also, as only a finite number of points are used the results are an approximation to the actual value on a valid domain.
The sum of gamma distributions with the same scale parameter is another gamma distribution with the overall shape parameter being the sum of the individual shape parameters. Verify for a specific case. (This example requires the statistics toolbox)
X1=linspace(0,10); Y1=gampdf(X1,2,1/2); N1=2; %(A)
X2=linspace(0,10); Y2=gampdf(X2,3,1/2); N2=3; %(B)
YT=YT./trapz(XT,YT); %Convert to density
axis([0 10 0 1/4])