Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Weighted fit using lsqnonlin
Date: Tue, 3 Nov 2009 09:48:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 24
Message-ID: <hcou8h$9tu$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1257241681 10174 172.30.248.38 (3 Nov 2009 09:48:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 3 Nov 2009 09:48:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1428858
Xref: news.mathworks.com comp.soft-sys.matlab:581993


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