When using the "fit" command with a startpoint vector, matlab will sometimes not fit the data and will instead just assume my startpoint is the best fit
조회 수: 14 (최근 30일)
이전 댓글 표시
I was fitting some data to a standard hyperbolic equation and I've been running into an issue. When I run the fit without a startpoint vector, I get a cfit object of wildly variable closeness of fit (as expected), but when I include a startpoint vector, I get out a cfit object with exactly my startpoint vector, regardless of how bad a fit that produces. I have several thousand data points and I'm trying to fit 3 parameters.
I had a similar issue with a much more complex equation that had several constants. I initially tried to have all the constants as variables and then just set the high and low bounds for those variables to be exactly the value of the constants, but instead matlab just returned a cfit with exactly my startpoint values for all the variables to be fit. When I instead put the values of the constants directly into the fit equation, the issue went away, but that's not an option for the hyperbolic fit. I've pasted code from both situations below, I haven't included my data because I don't know how to attach files.
Hyperbolic code:
y = "C/(x-theta) + yd";
S = [9.086e-09 0.04965 -5.991e-10];
[fit2, gof] = fit(T(1:100), X(1:100), y, 'StartPoint', S)
Brillouin code (faulty):
temp = 2;
y = sprintf(['Ms*((2*S+1)/(2*S) * coth(((2*S+1)/2)*Kd*x/T) - 1/(2*S) * ' ...
'coth(Kd*(x/T)/2))']);
S = [1.34e-4 .0045 1 temp]
R = [0 .0045 .8 0]
[fit2, gof] = fit(H2, M2, y, 'StartPoint', S, 'Lower', S-R, 'Upper', S+R)
Brillouin code ("fixed"):
temp = 2;
y = sprintf(['Ms*((2*S+1)/(2*S) * coth(((2*S+1)/2)*%e*x/%d) - 1/(2*S) * ' ...
'coth(%e*(x/%d)/2))'],1.34e-4, temp,1.34e-4, temp);
[fit2, gof] = fit(H2, M2, y)
댓글 수: 4
채택된 답변
Matt J
2024년 1월 25일
편집: Matt J
2024년 1월 25일
Numerical problems are created when your T and X data are very different orders of magnitude. Change the units of your X to something 1e10 times smaller:
load 'Hyperbolic Fit Data.mat'
T=A(:,1); X=A(:,2)*1e10;
y = "C/(x-theta) + yd";
S = [9.086e1 0.04965 -5.991];
[fit2, gof] = fit(T, X, y, 'StartPoint', S)
plot(fit2,T,X)
댓글 수: 2
Matt J
2024년 1월 25일
Glad to hear it, but please Accept-click the answer to indicate that it resolved your question.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
