How to set bounds for coefficents when fitting Exponential?

140 vues (au cours des 30 derniers jours)
Jaehwi Bong
Jaehwi Bong le 17 Juin 2019
I'd like to give boundary for coefficient(a, b and c). Whenever I run my fitting, it should give the coefficients within boundary. For instance, I want to get only b value of over 200 below 400.
I'm trying to make it with 'fitoptions', but it doesn't work in a code.
How should I do for that?
I attached my data file for example.
A=xlsread('A.xlsx');
t=A(:,1);
i=A(:,2)/10^(2);
ft = fittype('a*exp(-x/b)+c');
%options = fitoptions('ft', 'lower',[100000 400 10000], 'upper',[0 200 0]);
F=fit(t,i,ft) %, options)
General model:
F(x) = a*exp(-x/b)+c
Coefficients (with 95% confidence bounds):
a = 5.558e+04 (5.525e+04, 5.591e+04)
b = 373.5 (366.4, 380.7)
c = 5.171e+04 (5.135e+04, 5.207e+04)

Réponse acceptée

Steven Lord
Steven Lord le 17 Juin 2019
When I tell fitoptions to use the nonlinear least squares fitting method I can successfully create the options object. However when I try to use it MATLAB throws an error, (correctly) complaining that three elements of the lower bound vector are greater than the corresponding elements of the upper bound vector.
A=xlsread('A.xlsx');
t=A(:,1);
i=A(:,2)/10^(2);
ft = fittype('a*exp(-x/b)+c');
options = fitoptions('Method', 'NonlinearLeastSquares', ...
'Lower',[100000 400 10000], 'Upper',[0 200 0]);
F=fit(t,i,ft, options)
You attempted to use your custom fit type as the "library model" and simultaneously set options. If you want to do that, construct the default options first then set the Lower and Upper bounds on the resulting options object. This still has the problem that your Lower bounds are larger than your Upper bounds.
A=xlsread('A.xlsx');
t=A(:,1);
i=A(:,2)/10^(2);
ft = fittype('a*exp(-x/b)+c');
options = fitoptions(ft);
options.Lower = [100000 400 10000];
options.Upper = [0 200 0];
F=fit(t,i,ft, options)
If you were to swap the Lower and Upper bounds the fit function runs to completion, but plotting the resulting fit and your data shows that your limits on the parameters are not really realistic. The display of the fit object shows that all three parameters are fixed at your upper bounds.
A=xlsread('A.xlsx');
t=A(:,1);
i=A(:,2)/10^(2);
ft = fittype('a*exp(-x/b)+c');
options = fitoptions(ft);
options.Upper = [100000 400 10000];
options.Lower = [0 200 0];
F=fit(t,i,ft, options)
plot(F)
hold on
plot(t, i, 'o')
Omit your bounds from the fit call and the a and c parameters are outside your bounds but b is inside, and the fit looks much more in agreement with your data.
F2 = fit(t, i, ft)
figure
plot(F2)
hold on
plot(t, i, 'o')

Plus de réponses (0)

Catégories

En savoir plus sur Interpolation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by