Non-Linear Curve fit: Error using svd

2 Ansichten (letzte 30 Tage)
Adhitya Shreyas
Adhitya Shreyas am 5 Jul. 2021
Bearbeitet: Matt J am 26 Nov. 2021
I am conducting a non linear fit with multiple parameters, the data set is pretty big with 622 elements. The code I've used is shown below.
G = 6.67*(10^-11);
H = 73.8;
fun = @(b,X) ((100.*G.*(H^2)).*((b(1).^3)./X).*((log(abs(1+(X./b(2))))-((X./b(2))./((X./b(2))+1)))./(log(abs(1+(b(1)./b(2))))-((b(1)./b(2))./((b(1)./b(2))+1))))) + ((4.*pi.*G).*b(3).*b(4).*((X./(2.*b(4))).^2).*((besseli(0,(X./(2.*b(4)))).*besselk(0,(X./(2.*b(4)))))-(besseli(1,(X./(2.*b(4)))).*besselk(0,(X./(2.*b(4))))))) + (G.*22.665.*(b(5).^2).*b(6));
opts = statset('nlinfit');
%opts.RobustWgtFun = 'bisquare';
b0 = [5000; 3; 340; 90; 300; 600];
mdl = fitnlm(x,y,fun,b0,'Options',opts);
I get the following error:
Error using svd
Input to SVD must not contain NaN or Inf.
Error in internal.stats.isEstimable (line 108)
[V,Sx,U] = svd(X,0);
Error in NonLinearModel/fitter (line 1146)
internal.stats.isEstimable(eye(numel(model.Coefs)),'DesignMatrix',J_out,'TolSVD',TolSVD);
Error in classreg.regr.FitObject/doFit (line 94)
model = fitter(model);
Error in NonLinearModel.fit (line 1446)
model = doFit(model);
Error in fitnlm (line 99)
model = NonLinearModel.fit(X,varargin{:});
Error in Curve_Fit_Take_2 (line 9)
mdl = fitnlm(x,y,fun,b0,'Options',opts);
I believe the error is with some NaNs during processing, how do I go about this as I'm very sure there are no NaN values in my data set. Let me know if you also have a better way to find a non-linear fit.
Thanks in advance !!

Akzeptierte Antwort

Matt J
Matt J am 5 Jul. 2021
Bearbeitet: Matt J am 26 Nov. 2021
There are regions of the b(i) space where your model function will evaluate to a complex number, or to a non-finite value. You need to constrain the range of the search so that those b(i) are not tested. Possibly, you intend for all the b(i) to be positive for example. For that, you will probably need an alternative solver that supports bounds, e.g. lsqcurvefit.
  2 Kommentare
Adhitya Shreyas
Adhitya Shreyas am 9 Jul. 2021
Thank you Matt
yongguang zhou
yongguang zhou am 24 Nov. 2021
Thank you for helping me tackle similar problem as well.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Least Squares finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by