Path: news.mathworks.com!not-for-mail
From: "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Least squares fitting
Date: Tue, 13 May 2008 15:57:03 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 27
Message-ID: <g0cdof$85v$1@fred.mathworks.com>
References: <g0ccfp$jd9$1@fred.mathworks.com>
Reply-To: "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
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 1210694223 8383 172.30.248.35 (13 May 2008 15:57:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 13 May 2008 15:57:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:468185


"Zaira " <Zaira.Girbau-Garcia@jrc.it> wrote in message <g0ccfp$jd9
$1@fred.mathworks.com>...
> I need to find the coefficients k1-k6 of the following equation:
> 
> P = G*(k1 + k2*T + k3*log(G) + k4*(log(G)).^2 + k5*T*log(G)+
> k6*T*(log(G)).^2+k7*T.^2);
> 
> The experimental data I have are P, G and T.
> 
> Is there any MATLAB function in order to obtain the
> coefficients using least-squares fitting? 
> Do I need the Curve Fitting Toolbox?
> 
> Thank you very much,
> Zaira
-----------
  The undetermined k coefficients appear linearly in your expression, so this 
is an ordinary problem in linear regression for which you can use the matlab 
backslash operator.  If P, G, and T are column vectors of the same length, do 
this:

 A = G.*[ones(size(G)),T,log(G),log(G).^2, ...
        T.*log(G),T.*log(G).^2,T.^2];
 k = A\P;

Roger Stafford