Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: Least squares fitting

Subject: Least squares fitting

From: Zaira

Date: 13 May, 2008 15:35:21

Message: 1 of 3

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



Subject: Re: Least squares fitting

From: John D'Errico

Date: 13 May, 2008 15:55:06

Message: 2 of 3

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

This is a linear least squares problem. You can
use my polyfitn to do the fitting. Find it on the
file exchange.

http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?
objectId=10065&objectType=FILE

Assuming that P,G,T are all column vectors,

LG = log(G);
model = polyfitn([G,LG,T],P,'G, G*T, G*LG, G*LG^2, G*LG*T, G*T*LG^2,
G*T^2');

HTH,
John

Subject: Re: Least squares fitting

From: Roger Stafford

Date: 13 May, 2008 15:57:03

Message: 3 of 3

"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

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
fitting Zaira 13 May, 2008 11:40:37
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
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 Disclaimer prior to use.
Related Topics