Thread Subject: Weighted fit using lsqnonlin

Subject: Weighted fit using lsqnonlin

From: Ida Haggstrom

Date: 3 Nov, 2009 09:48:01

Message: 1 of 2

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

Subject: Weighted fit using lsqnonlin

From: John D'Errico

Date: 3 Nov, 2009 11:16:01

Message: 2 of 2

"Ida Haggstrom" <ida_haggstrom@yahoo.se> wrote in message <hcou8h$9tu$1@fred.mathworks.com>...

> 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?

Yes.

John

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com