help-octave
[Top][All Lists]
Advanced

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

Re: 1/x fit


From: Willem Atsma
Subject: Re: 1/x fit
Date: Tue, 13 Mar 2018 12:46:00 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0

Hello Pierre,

Your formulation has some conditioning issues. Plot the raw data and
your initial data together and you will probably see they are pretty
close together. To fix your approach add some tolerance options to
fminsearch and turn verbosity on:

function y=fitcal(p)
   global xraw yraw;
   yfit=p(1)+1.0./(p(2)*xraw);
   y = sqrt(sum((yraw-yfit).^2));
end

global xraw yraw;

sx0=[100,0.00015];
xraw=sort(rand(100,1))*3;
yraw=80 + (1/0.00013)./xraw;

ops = optimset;
ops.Display = 'iter';
ops.TolX = 1e-9;
[sx,fxval]=fminsearch(@fitcal,sx0,ops);

Note also that p(2) would probably do better in the numerator. A better
approach would be to fit yraw and 1./xraw using the polyfit function:

P = polyfit(1./xraw, yraw, 1);

which give accurate estimates.

Willem


On 2018-03-13 11:00 AM, address@hidden wrote:
> I have some data, call it xraw and yraw which followsa 1/x curve.
> I'm attemptingto minimizea function yraw-yfit, so as to get the
> parameters 'p'.
>
> function y=fitcal(p)
>    global xraw yraw;
>    yfit=p(1)+1.0./(p(2)*xraw);
>    y = sqrt(sum((yraw-yfit).^2));
> end
>
> I'm attempting to use fminsearch, such that my call to the function is:
>
> global xraw yraw;
> ...
> sx=[100,0.00015];
> xraw=TXI;
> yraw=RXI;
> [sx,fxval]=fminsearch(@(sx)fitcal(sx),sx);
>
> Nothing that I try changes sx; i.e. the fitter always returns the initial
> values, so I'm assuming that my fit is failing.




reply via email to

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