Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Solving simultaneously for two unknowns for fitting the data with a model

Subject: Solving simultaneously for two unknowns for fitting the data with a model

From: Suyash

Date: 6 Nov, 2012 00:24:07

Message: 1 of 3

Hello,

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?

If there are any examples and help, I would really appreciate it!

Thanks!

S

Subject: Solving simultaneously for two unknowns for fitting the data with a model

From: Roger Stafford

Date: 6 Nov, 2012 02:59:09

Message: 2 of 3

"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

Subject: Solving simultaneously for two unknowns for fitting the data with a model

From: Suyash

Date: 7 Nov, 2012 23:19:14

Message: 3 of 3

Thank you for the reply, I think it is optimal in my case to solve for the p and k independently to using fminsearch! Thanks,

S

"Roger Stafford" wrote in message <k79udt$g69$1@newscl01ah.mathworks.com>...
> "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

Tags for this Thread

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.

Contact us