Lsqcurvefit to gamma variate function

4 views (last 30 days)
Maria
Maria on 5 Mar 2014
Edited: Matt J on 5 Mar 2014
Hi,
I have been trying to use lsqcurvefit to fit to a gamma variate function without much luck. It appears to be very sensitive to starting conditions. I have tried altering the lower and upper bounds carefully but it still appears to fail delivering a good fit. What am I doing wrong? Any help is appreciated.
Maria
% startparams
k(1)=26.5146 + 5i;
k(2)=48.5670 + 0.0000000i;
k(3)=-0.12 - 0.1300i; % VERY sensitive
k(4)=38.7744e+01 + 19.2626e+02i;
a = lsqcurvefit(@gma_var,k,t,y,2,2000);
b= lsqcurvefit(@gma_var,k,t,y2,2,2000);
Func= a(1)*((t-a(2)).^a(3)).*exp(-(t-a(2))/a(4));
Func_t= b(1)*((t-b(2)).^b(3)).*exp(-(t-b(2))/b(4));
% gamma variate function
function out=gma_var(x,xdata)
F= x(1)*((xdata-x(2)).^x(3)).*exp(-(xdata-x(2))/x(4));
out=F;
end

Answers (1)

Matt J
Matt J on 5 Mar 2014
Edited: Matt J on 5 Mar 2014
  1. Your upper and lower bounds must be specified as length 4 vectors
  2. Your unknowns x(i) and their initial guesses k(i) cannot be complex numbers
  3. To derive a good initial guess, you might start by fitting the log of your model equation,
logF = z(1)+z(3)*log(xdata-z(2)) - z(4)*(xdata + z(2))
where I've made the change of variables,
z(1)=log(x(1)),
z(2)=x(2),
z(3)=x(3),
z(4)=1/x(4).
This equation is linear w.r.t all but z(2). FMINSPLEAS ( available here ) would probably do a good job with it.

Categories

Find more on Matrix Computations in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!