## How to sum two probability density functions?

### Jules Ray (view profile)

on 25 Feb 2019
Latest activity Commented on by John D'Errico

on 25 Feb 2019

### ANKUR KUMAR (view profile)

hello
I have created two probability density functions using this formula:
I would like to sum two of these pdfs and also substract both, but I have not idea how to do it.
pd = fitdist(L1.Z(:),'Normal');
x_pdf = [min(L1.Z(:)):0.01:max(L1.Z(:))];
y = pdf(pd,x_pdf);
plot(x_pdf,y,'-')

### ANKUR KUMAR (view profile)

on 25 Feb 2019

"sum two of these pdfs and also substract both"?
Are you pretty sure to add the pdfs?
My suggestion is to first add data and then plot the pdf in the regular fashion.
If you facing some issues with plotting pdf, use join the tops of histograms of the data and convert y axis into percentage. This also gives you the probability of occurence of a number in your data.

Jules Ray

### Jules Ray (view profile)

on 25 Feb 2019
Tnnks Ankur
Yes, I have been trying to perform operations with PDF's but seems to be simplest way perform these operation on the data and then calculate the PDF. I found a function (see link) that perfom sum between pdf's. The issue is when I compare results of both (working with the original data and by summing pdf's) both give different results and can only performed when matrix are equal size both. Just summing the data and applying pdf give a quite bell shaped curve, instead when suming both gives a bimodal curve. I dont know how to explain this.
you reply suggest "My suggestion is to first add data and then plot the pdf in the regular fashion", how would you add the data if the matrix are n*m and l*k both with different numbers of rows and cols?
ANKUR KUMAR

### ANKUR KUMAR (view profile)

on 25 Feb 2019
There is no any compulsion of using the pre-defined pdf funciton in MATLAB.
PDF is nothing but the probability of occurence of each element.
Let's A is a matrix of m*n size. PDF of A is exactly same as the PDF of A(:).
So, if you wish to sum-up two data sets of different dimension, just convert into row matrices and then merge it up.
A=rand(5,6);
B=rand(7,8);
C=[A(:) ; B(:)];
DIrectly plot the PDF of matrix C. PDF just give the percentage of occurnce of element, nothing else.
ANKUR KUMAR

### ANKUR KUMAR (view profile)

on 25 Feb 2019
One of the simplest way to plot Probability Distribution Function is use first draw histogram and then join their tops, follwed by converting Y axis into percentage.

### Jules Ray (view profile)

on 25 Feb 2019
Edited by Jules Ray

### Jules Ray (view profile)

on 25 Feb 2019

Great
that was very clarifying
Just a quick question, this would be the example for add two pdf's: C=[A(:) ; B(:)];
Thanks again

John D'Errico

on 25 Feb 2019