Non-Linear Curve fit: Error using svd

조회 수: 2 (최근 30일)
Adhitya Shreyas
Adhitya Shreyas 2021년 7월 5일
편집: Matt J 2021년 11월 26일
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 !!

채택된 답변

Matt J
Matt J 2021년 7월 5일
편집: Matt J 2021년 11월 26일
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
Adhitya Shreyas
Adhitya Shreyas 2021년 7월 9일
Thank you Matt
yongguang zhou
yongguang zhou 2021년 11월 24일
Thank you for helping me tackle similar problem as well.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Least Squares에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by