exp(-b/x) fit, inf problem when fitting
이전 댓글 표시
I am trying to fit some data with the model: exp(-b/x); When x goes to zero, y should go to zero as well since anything power negative infinity is zero. However Matlab sees the infinity and terminates everything. Here is my code:
vv=data(:,1);
ii=data(:,2);
g = fittype('exp(-b/x)');
f0 = fit(vv,ii,g);
xx = linspace(-1,1);
plot(vv,ii,'o',xx,f0(xx),'r-');
grid('on')
댓글 수: 5
Mathieu NOE
2021년 2월 25일
hello
could you share the data as well ?
tx
Basil Eldeeb
2021년 2월 26일
Mathieu NOE
2021년 2월 26일
yes , your data show a very linear trend
how can you expect to fit an exponential model to these data ? it will never work
Basil Eldeeb
2021년 2월 26일
Mathieu NOE
2021년 2월 26일
not sure it's really a good model...

data = readmatrix('data.txt');
x = data(:,1);
y = data(:,2);
% exponential fit method
% model : y = exp(-b/x)
f = @(b,x) exp(b./x);
obj_fun = @(params) norm(f(params(1), x)-y);
sol = fminsearch(obj_fun, -0.1);
b_sol = sol(1)
y_fit = f(b_sol, x);
figure
plot(x,y,'r',x,y_fit,'-.k');
legend('data','exp fit');
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 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!
