```Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Estimation of variables to minimize the sum of residuals
Date: Tue, 6 Nov 2012 03:21:09 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 14
Message-ID: <k79vn5\$kdj\$1@newscl01ah.mathworks.com>
References: <k79nrs\$oss\$1@newscl01ah.mathworks.com>
NNTP-Posting-Host: www-05-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1352172069 20915 172.30.248.37 (6 Nov 2012 03:21:09 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 6 Nov 2012 03:21:09 +0000 (UTC)
Xref: news.mathworks.com comp.soft-sys.matlab:782121

"Prakhar " <prakhar_cool@yahoo.com> wrote in message <k79nrs\$oss\$1@newscl01ah.mathworks.com>...
> res = x - f
> (e.g.: res(1) = x(1) - (a + b*y(1) + c*y(1)^2).
> Define sum of square of residuals as:
> s = sum(res.^2).
> Now, i need to find variables a, b, c in such a way so that the sum of residuals 's' is minimum.
- - - - - - - - -
This is a simple problem in linear regression.  We assume x and y are column vectors as shown.  Do:

abc = [ones(size(y)),y,y.^2]\x;

where 'abc' will be a three-element column vector containing the optimum a, b, and c coefficients in that order.

Roger Stafford
```