필터 지우기
필터 지우기

Complex value computed by model function, fitting cannot continue. Try using or tightening upper and lower bounds on coefficients.

조회 수: 14 (최근 30일)
Hello, I really need some help on data fitting. I would like to fit my data custom equation:a+b*exp((-(x/c))^d. I try to use upper and lower bounds on coefficients but it does not work.If anyone can tell me what to do to resolve this I would greatly appreciate it.
  댓글 수: 4
Torsten
Torsten 2024년 6월 3일
Because of the error message and the overfitting, I suspect
a+b*exp(-(x/c)^d)
instead of
a+b*exp((-(x/c))^d
is meant.
Daniel Jiao
Daniel Jiao 2024년 6월 4일
@Torsten Thanks lot, I'll check it. This equation is given by an article, so it's a theoretical formula, but yeah, I'll check whether it's correct, thanks so much!

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

채택된 답변

Matt J
Matt J 2024년 6월 3일
편집: Matt J 2024년 6월 3일
fminspleas from this FEX download,
is helpful for these kinds of models.
[x,y]=readvars('200ms_SD.xlsx');
flist={1,@(c,x) exp(-c*x)};
[c,ab]=fminspleas(flist,+1,x,y);
a=ab(1);
b=ab(2);
f=@(x)a+b*exp(-c*x);
xf=linspace(min(x),max(x));
plot(x,y,'.c',xf,f(xf)); axis padded; legend Data Fit
  댓글 수: 3
Daniel Jiao
Daniel Jiao 2024년 6월 4일
Thanks a lot for this answer, it really give me some ideas and confidence, as the comment you mentioned above, I just try to use fit() and fittype(), like:
ft = fittype( 'a+b*exp((-(x/c))^d)', 'independent', 'x', 'dependent', 'y' );
fitobject = fit(x,y,ft,'lower',[-1,0,0.002,0],'upper',[0,3,0.005,1]);
and I also use the curve fitting toolbox. Just some basic way, since it was first time I try to do curve fitting.
Anyway that's really helpful! Thanks so much for that, and I'll try it!
Matt J
Matt J 2024년 6월 4일
You're welcome, but when you've decided upon a solution, please Accept-click the appropriate answer.

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

추가 답변 (1개)

Mathieu NOE
Mathieu NOE 2024년 6월 3일
hello
a very basic code using only fminsearch (no toolbox required )
I preferred to smooth a bit your data (otherwise it looks more like a cloud) but it's not absolutely needed - but you end up with other parameters after the fit
hope it helps !
data = readmatrix('200ms_SD.xlsx');
x = data(:,1);
y = data(:,2);
[x,ia,ic] = unique(x);
y = y(ia);
ys = smoothdata(y,'gaussian',100);
% curve fit using fminsearch
% model a+b*exp((-(x/c))^d
f = @(a,b,c,d,x) a + b.*exp(-(x/c).^d);
obj_fun = @(params) norm(f(params(1), params(2), params(3), params(4),x)-ys);
sol = fminsearch(obj_fun, [ys(end),(max(ys)-ys(end)),1,1]);
Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 1.159572
a_sol = sol(1)
a_sol = 0.0903
b_sol = sol(2)
b_sol = 0.5209
c_sol = sol(3)
c_sol = 0.0028
d_sol = sol(4)
d_sol = 0.1143
y_fit = f(a_sol, b_sol, c_sol, d_sol, x);
R2 = my_R2_coeff(ys,y_fit); % correlation coefficient
plot(x,y, 'k.',x,ys,'r',x, y_fit,'b-')
title([' Fit / R² = ' num2str(R2) ], 'FontSize', 15)
legend('raw data','smoothed','fit');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function R2 = my_R2_coeff(data,data_fit)
% R2 correlation coefficient computation
% The total sum of squares
sum_of_squares = sum((data-mean(data)).^2);
% The sum of squares of residuals, also called the residual sum of squares:
sum_of_squares_of_residuals = sum((data-data_fit).^2);
% definition of the coefficient of correlation (R squared) is
R2 = 1 - sum_of_squares_of_residuals/sum_of_squares;
end
  댓글 수: 1
Daniel Jiao
Daniel Jiao 2024년 6월 4일
Hello,thanks a lot for the answer, it's really helpful! I'll try to read and try the code you offered! My original code is much more basic, since I'm just a beginner.
Thanks again that I really got some knowledge from you!

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

카테고리

Help CenterFile 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!

Translated by