help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: i just want to use nonlinear curve fitting function , what should i


From: Jaroslav Hajek
Subject: Re: i just want to use nonlinear curve fitting function , what should i do?
Date: Mon, 18 Jan 2010 07:39:00 +0100

2010/1/18 Tatsuro MATSUOKA <address@hidden>:
> Hello
>
> --- Jaroslav Hajek wrote:
>
>> In Octave 3.2.0 and higher, nonlinear curve fitting can be done
>> through the function fsolve.
>> To use in a stand-alone program, you need to link it with the Octave
>> libraries, and then take these steps:
>
> Just from curiosity, I would like to know how to do nonlinear curve fitting 
> through the function
> fsolve.
>
> Are the followings right ?
> 1.Meke residual sum of squares
> lsq=sum(yi-f(xi,p))^2
> p is a parameter vector assume dimension N
>
>
> 2. Make simultaneous equations from parameter derivatrive
> make N simultaneous equations, d lsq/ d p[i ] =0
>
> 3. solve non linear simultaneous equations by fslove
>
> Regards
>
> Tatsuro

No, that is not necessary. Nonlinear curve fitting is just solving an
overdetermined system of nonlinear equations (i.e. more equations than
variables), and that's all - you make a function that calculates the
equation residuals and feed it to fsolve. You can, optionally, also
compute the Jacobian (a rectangular matrix, in this case), if you can
do it more efficiently than via finite differences.
The system is solved for in a least squares sense. It's analogous to
how the \ operator works.

Here's an example fitting the model y = exp(a*x) + b to an
artificially created dataset:

b0 = 3;
a0 = 0.2;
x = 0:.5:5;
noise = 1e-5 * sin (100*x);
y = exp (-a0*x) + b0 + noise;
c_opt = [a0, b0];
tol = 1e-5;

[c, fval, info, output] =  fsolve (@(c) (exp(-c(1)*x) + c(2) - y), [0, 0]);

-- 
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz


reply via email to

[Prev in Thread] Current Thread [Next in Thread]