<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264821</link>
    <title>MATLAB Central Newsreader - Weighted fit using lsqnonlin</title>
    <description>Feed for thread: Weighted fit using lsqnonlin</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Tue, 03 Nov 2009 09:48:01 -0500</pubDate>
      <title>Weighted fit using lsqnonlin</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264821#691665</link>
      <author>Ida Haggstrom</author>
      <description>Hi!&lt;br&gt;
&lt;br&gt;
I've seen a post regarding weighted non-linear fitting using lsqnonlin at &lt;a href=&quot;http://www.mathworks.com/support/solutions/en/data/1-18DGY/index.html?solution=1-18DGY.&quot;&gt;http://www.mathworks.com/support/solutions/en/data/1-18DGY/index.html?solution=1-18DGY.&lt;/a&gt; &lt;br&gt;
&lt;br&gt;
I wonder if the following produces the same results, i.e. a weighted fit... &lt;br&gt;
Say you have a vector yIn and want to fit it to y = a*x + b*exp(-c*x) as a simple example. &lt;br&gt;
&lt;br&gt;
If you have a main function like this:&lt;br&gt;
################################&lt;br&gt;
function paramFitted = Main(x,yIn)&lt;br&gt;
global yIn x&lt;br&gt;
param0 = [1 1 1];&lt;br&gt;
paramFitted = lsqnonlin(@myFitFunction, param0);&lt;br&gt;
%--------------------------------------------------------------------&lt;br&gt;
function res = myFitFunction(paramIn)&lt;br&gt;
global yIn x&lt;br&gt;
y = paramIn(1)*x + paramIn(2)*exp(-paramIn(3)*x);&lt;br&gt;
res = y - yIn;&lt;br&gt;
################################&lt;br&gt;
&lt;br&gt;
will not lsqnonlin minimize the square of (y-yIn)? And to introduce a weighted fit, can you not just change to:&lt;br&gt;
res = (y - yIn).*weights;&lt;br&gt;
for a given weight vector? Is this a correct way to do a weighted fit using lsqnonlin? Thanks!&lt;br&gt;
Ida</description>
    </item>
    <item>
      <pubDate>Tue, 03 Nov 2009 11:16:01 -0500</pubDate>
      <title>Re: Weighted fit using lsqnonlin</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264821#691683</link>
      <author>John D'Errico</author>
      <description>&quot;Ida Haggstrom&quot; &amp;lt;ida_haggstrom@yahoo.se&amp;gt; wrote in message &amp;lt;hcou8h$9tu$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&lt;br&gt;
&amp;gt; will not lsqnonlin minimize the square of (y-yIn)? And to introduce a weighted fit, can you not just change to:&lt;br&gt;
&amp;gt; res = (y - yIn).*weights;&lt;br&gt;
&amp;gt; for a given weight vector? Is this a correct way to do a weighted fit using lsqnonlin? &lt;br&gt;
&lt;br&gt;
Yes.&lt;br&gt;
&lt;br&gt;
John</description>
    </item>
  </channel>
</rss>

