```Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Solving simultaneously for two unknowns for fitting the data with a model
Date: Tue, 6 Nov 2012 02:59:09 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 20
Message-ID: <k79udt\$g69\$1@newscl01ah.mathworks.com>
References: <k79lb7\$gtr\$1@newscl01ah.mathworks.com>
NNTP-Posting-Host: www-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1352170749 16585 172.30.248.47 (6 Nov 2012 02:59:09 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 6 Nov 2012 02:59:09 +0000 (UTC)
Xref: news.mathworks.com comp.soft-sys.matlab:782117

"Suyash" wrote in message <k79lb7\$gtr\$1@newscl01ah.mathworks.com>...
> Suppose my model is an equation similar to a power function, Y = k.(Ix^p - Th^p) in which, k, p, and Th are constants. I know the values of Ix and corresponding Y. Both Ix and Y are an array. I want to fit my data (Ix ~ Y) with the equation I mentioned earlier (i.e.  Y = k.(Ix^p - Th^p) ). How do iterate simultaneously on the values of p and k to find the best least-squares fit?
- - - - - - - - -
You are given the vectors Ix and Y and the fixed scalar Th and wish to adjust the parameters k and p so as to minimize the quantity

S = sum(k*(Ix.^p-Th^p)-Y).^2 .

Do I state your problem correctly?

For any given value of p the value of k which minimizes S is

k = sum(Y.*(Ix.^p-Th^p))/sum((Ix.^p-Th^p).^2)

as one can see by taking the partial derivative of S with respect to k.

By substituting this expression for k one obtains S as a function of the single parameter p.  If you know of upper and lower bounds for p, you can then use matlab's 'fminbnd' to find a minimum.

Alternatively you can use 'fminsearch' to find the minimum using either the single-variable problem with p using the above substitution for k, or the two-variable problem with both p and k as variables.  (The single-variable usage is probably more efficient in this case.)

Roger Stafford
```