Thread Subject: Weighted fit using lsqnonlin

Subject: Weighted fit using lsqnonlin

From: Ida Haggstrom

Date: 3 Nov, 2009 09:47:01

Message: 1 of 1

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

Tags for this Thread

Everyone's Tags:

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.

Tag Activity for This Thread
Tag Applied By Date/Time
lsqnonlin weigh... Ida Haggstrom 3 Nov, 2009 04:49:02
rssFeed for this Thread

Contact us at files@mathworks.com