I'm estimating a probability density function (pdf) using matlab.
The code is like this
xi = -2:0.1:2;
a1 = normpdf(xi, 1, 0.3);
a2 = normpdf(xi, -1, 0.3);
subplot(211);
plot(xi, a1+a2);
[f, xs] = ksdensity(a1+a2);
subplot(212);
plot(xs, f);
and pics like this

You see the estimation is not working at all.
So what's wrong here? BTW is there other pdf estimation methods in matlab?
Is this closer to what you expect?
The
ksdensityfunction expects a vector of samples from the distribution, whereas you were feeding it the values of the probability density function.