Curve Fitting Problem
Peter Cloetens
cloetens at esrf.fr
Fri Jun 27 02:57:32 CDT 2008
My suggestions would be:
either:
treat this as a non-linear fitting problem with 1 unknown and use for
example "leasqr" from the octave-forge package optim
or:
solve explicitly for your unknown "k" and you end up with an explicit
solution.
Something like:
Minimize the cost function
cost(k) = sum |y_i - k^2/4*x_i^2 - k*p*x_i - p^2|^2
with respect to k
Derivation leads to a cubic (third order) equation in k:
a*k^3 + b*k^2 +c*k + d = 0
with
a = 1/8*sum(x_i^4)
b = 3/4*p*sum(x_i^3)
c = 3/2*p^2*sum(x_i^2) - 1/2*sum(y_i*x_i^2)
d = -p*sum(y_i*x_i) + p^3*sum(x_i)
The cubic equation can be solved with the octave function fzero or
explicitly with one of the methods described here:
http://en.wikipedia.org/wiki/Cubic_equation
Peter
A. Kalten wrote:
> Hello,
>
> I need some advice on solving a curve fitting problem.
>
> Ordinarily, a curve fitting algorithm, such as polyfit
> or wpolyfit in octave, will determine the coefficients of a
> polynomial that best fits the empirical data. If the model
> is a second degree polynomial, a x^2 + b x + c, the algorithm
> will return the best coefficients a, b, and c.
>
> The trouble I am having is that I need to fit a second
> degree polynomial where some of the coefficients are
> either already known or include another known parameter
> as a factor. For example, I need to find the best value
> for k in this equation:
>
> k^2/4 x + k p x + p^2
>
> where p is a known quantity.
>
> Although there are three coefficients, there is really
> only one unknown parameter, that is k. Using polyfit from octave
> will return a, b, and c where a = k^2/4, b = k p, and c = p^2.
>
> Solving the two equations for k gives values that
> are significantly different (they differ in the second
> decimal place).
>
> Is there an algorithm available that allows some of the
> parameters of the model to be predetermined or to include
> some predetermined factor?
>
> I suspect that the only solution would be to write a
> custom least squares program.
>
> AK
>
> _______________________________________________
> Help-octave mailing list
> Help-octave at octave.org
> https://www.cae.wisc.edu/mailman/listinfo/help-octave
More information about the Help-octave
mailing list