|
Hi!
I've seen a post regarding weighted non-linear fitting using lsqnonlin at http://www.mathworks.com/support/solutions/en/data/1-18DGY/index.html?solution=1-18DGY.
I wonder if the following produces the same results, i.e. a weighted fit...
Say you have a vector yIn and want to fit it to y = a*x + b*exp(-c*x) as a simple example.
If you have a main function like this:
################################
function paramFitted = Main(x,yIn)
global yIn x
param0 = [1 1 1];
paramFitted = lsqnonlin(@myFitFunction, param0);
%--------------------------------------------------------------------
function res = myFitFunction(paramIn)
global yIn x
y = paramIn(1)*x + paramIn(2)*exp(-paramIn(3)*x);
res = y - yIn;
################################
will not lsqnonlin minimize the square of (y-yIn)? And to introduce a weighted fit, can you not just change to:
res = (y - yIn).*weights;
for a given weight vector? Is this a correct way to do a weighted fit using lsqnonlin? Thanks!
Ida
|