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
Show older comments
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)
Accepted Answer
More Answers (0)
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!