Search code examples
matlabcurve-fittingfactorialpoisson

Matlab. Poisson fit. Factorial


I have a histogram that seems to fit a poisson distribution. In order to fit it, I declare the function myself as follows

xdata; ydata; % Arrays in which I have stored the data. 
%Ydata tell us how many times the xdata is repeated in the set.

fun= @(x,xdata) (exp(-x(1))*(x(1).^(xdata)) )/(factorial(xdata)) %Function I 
% want to use in the fit. It is a poisson distribution.

x0=[1]; %Approximated value of the parameter lambda to help the fit

p=lsqcurvefit(fun,x0,xdata,ydata); % Fit in the least square sense

I find an error. It probably has to do with the "factorial". Any ideas?


Solution

  • Factorial outputs a vector from vector xdata. Why are you using .xdata in factorial?

    For example:

    data = [1 2 3];
    

    factorial(data) is then [1! 2! 3!].

    Try ./factorial(xdata) (I cannot recall if the dot is even necessary at this case.)