NaN/Inf/Complex value warning using "fit"

8 Ansichten (letzte 30 Tage)
Fabs
Fabs am 16 Mär. 2016
Bearbeitet: Stephan am 21 Jun. 2018
Hi all,
I'm interpolating between points using "fit" and get the warning
Warning: NaN, Inf, or complex value detected in startpoint;
choosing random starting point instead.
> In curvefit.attention.Warning/throw (line 30)
In fit>iFit (line 299)
In fit (line 108)
In fit_test (line 12)
The things is, (I'm pretty sure) there is no NaN, Inf, or complex value involved. Also weird, the fit seems to be different every time I execute the code (and goes completely haywire from time to time). If the first row in the data is removed, the warning disappears.
I included a code snippet that replicates my problem:
clear
close
% data
data = [1,4.26993;2,3.316751;3,3.130543;4,2.785851;5,2.462480;6,2.220899;7,1.991443;8,1.713285;9,1.591862;10,1.426485;11,1.329915;12,1.212978;13,1.163305;14,1.099329;15,1.042767;16,0.9620282;17,0.9086622;18,0.8804317;19,0.8365277;20,0.8281681;21,0.7897473;196,0.08825890;197,0.08764152;198,0.08784707;199,0.08867170;200,0.09054118];
% if first row is removed, no warning appears
% data(1,:) = [];
% fit two-term exponential function to data
data_fit = fit(data(:,1),data(:,2),'exp2');
% plot fitted data and curve
figure
plot(data_fit,data(:,1),data(:,2),'predfunc')
Any ideas? Thanks!

Antworten (3)

Antoine de Comité
Antoine de Comité am 16 Nov. 2016
I have the same problem and i'm pretty sure there is no NaN, Inf or complex values in my data. Did you find what was the problem?

Stephan
Stephan am 21 Jun. 2018
Hi,
if you do not specify any start points, this can happen, because the start Points are choosen by a heuristic normally. You can avoid this warning by adding a vector for the start point option:
data_fit = fit(data(:,1),data(:,2),'exp2', 'StartPoint',[0,0,0,0]);
In your case this example will work without a warning.
Best regards

Jos (10584)
Jos (10584) am 21 Jun. 2018
Your model is ill-suited to this set of data, as you can verify by checking the output of data_fit. When you provide a proper starting point, the warning naturally disappears:
data_fit = fit(data(:,1),data(:,2),'exp2','Startpoint',[0 1 0 1]);
  1 Kommentar
Stephan
Stephan am 21 Jun. 2018
Bearbeitet: Stephan am 21 Jun. 2018
Note that with [0 1 0 1] as start point you get this result:
using [0 0 0 0] will give:
Best regards
Stephan

Melden Sie sich an, um zu kommentieren.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by