Path: news.mathworks.com!not-for-mail
From: "John D'Errico" <woodchips@rochester.rr.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Curve fitting problem
Date: Tue, 16 Dec 2008 23:56:02 +0000 (UTC)
Organization: John D'Errico (1-3LEW5R)
Lines: 24
Message-ID: <gi9f6i$okl$1@fred.mathworks.com>
References: <gi6gvi$jlc$1@fred.mathworks.com> <gi7tie$jau$1@fred.mathworks.com> <gi91ji$b7a$1@fred.mathworks.com>
Reply-To: "John D'Errico" <woodchips@rochester.rr.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1229471762 25237 172.30.248.35 (16 Dec 2008 23:56:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 16 Dec 2008 23:56:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869215
Xref: news.mathworks.com comp.soft-sys.matlab:507409


"Tazmusica " <tazmusica2@deletethis.gmail.com> wrote in message <gi91ji$b7a$1@fred.mathworks.com>...
> "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gi7tie$jau$1@fred.mathworks.com>...
> > "Tazmusica " <tazmusica2@deletethis.gmail.com> wrote in message <gi6gvi$jlc$1@fred.mathworks.com>...
> > > I am trying to fit several data sets to a sum of Lorentzians. I have written code that uses fminsearch. For data that is a sum of two Lorentzians, it
> > > seems to work fine. When I try and fit data that is a sum of 3 or more Lorentzians, it seems to have difficulty. ........
> > 
> >   Here's one suggestion that might help.  You can, in effect, reduce the total number of parameters you are dealing with by writing your function to be minimized in such a way as to automatically adjust the a-parameters and vshift to achieve a minimum square.  Your function of Lorenzians is linear in these four parameters and for any given value of the other six, a minimum with respect to these four can always be achieved without iteration.  It is simply the solution to a set of four linear equations.  So your function can be rewritten to always achieve such a minimum and therefore would involve only the other six parameters to be handed to fminsearch for variation.  Six parameters is a whole lot easier for fminsearch to deal with than ten in terms of running into blind alleys or wandering around aimlessly.
> > 
> > Roger Stafford
> 
> Roger,
> Thank you for the suggestion. I can see that the Lorentzian is linear in the a and vshift terms, and I see that this reduces the number of parameters that fminsearch has to deal with. So if the function of Lorentzians were called L(x), and each lorentzian in the sum were l(x), then L(x)=a1*l1(x)+a2*l2(x)+a3*l3(x)+vshift. What I am unclear on is how to rewrite the function to always achieve the minimum of the a and vshift values. I can see where it should be the solution to a system of linear equations that would automatically minimize the a and vshift values, but I guess I am not seeing how I can get this into a form that I can pass to fminsearch using only the remaining 6 parameters. I apologize for being so obtuse, and I thank you for all of your help.


By the way, the method that Roger has suggested
is exactly what is implemented in fminspleas. You 
can find it here on the file exchange:

http://www.mathworks.com/matlabcentral/fileexchange/10093

I've already done much of the work for you.

HTH,
John