%In physics, a three-parameter Lorentzian function is often used, as follows:
% f(x;x0,?,I) = I/(1 + ( (x-x0)/? )^2)
% I: is the height of the peak.
% x0: is the location paremeter, specifying the location of the peak.
% ?: is the scale parameter which specifies the half-width at half-maximum (HWHM).
% ? is also equal to half the interquartile range and is sometimes called the probable error.
%If you would want,e. g., to ?t a Lorentzian y = a1/((x ? a2)^2 + a3) to a data set Xi, Yi,
%you should define in MATLAB a function resulting in the sum of the squared residuals
% a(1)= I
% a(2)= x0
% a(3)= ?
function chisq = devsum(a,X,Y)
%global X Y
%a
%Lorentzian = a(1)./((X-a(2)).^2+a(3)); % the pdf definition
Lorentzian = a(1)./( 1 + ( (X-a(2))./a(3) ).^2); % wikipeida definition
%X'
csq = (Y - Lorentzian).^2;
chisq = sum(csq);
return