exp(-b/x) fit, inf problem when fitting

4 visualizaciones (últimos 30 días)
Basil Eldeeb
Basil Eldeeb el 25 de Feb. de 2021
Comentada: Basil Eldeeb el 2 de Mzo. de 2021
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 comentarios
Basil Eldeeb
Basil Eldeeb el 26 de Feb. de 2021
supposedly when the exponent is quite small it will behave linearly to a first order. The model is more complex, actually, I am just facing a problem with the exp(-b/x) term. I want matlab to evaluate exp(-Inf) without giving error. The other answer shows promise. However it gave an error, you can see it in my response
Mathieu NOE
Mathieu NOE el 26 de Feb. de 2021
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');

Iniciar sesión para comentar.

Respuesta aceptada

Matt J
Matt J el 25 de Feb. de 2021
Editada: Matt J el 25 de Feb. de 2021
When x goes to zero, y should go to zero as well since anything power negative infinity is zero.
Only if b>=0.
g = fittype('exp(-b/x)', 'options', fitoptions('Lower',0) );
  5 comentarios
Matt J
Matt J el 1 de Mzo. de 2021
Editada: Matt J el 1 de Mzo. de 2021
You should divide the data into two sets and fit each one separately, e.g.,
pos=vv>0; neg=~pos;
fpos = fit(vv(pos),ii(pos),gpos,options);
fneg = fit(vv(neg),ii(neg),gneg,options);
Basil Eldeeb
Basil Eldeeb el 2 de Mzo. de 2021
I appreciate it, thank you for the help!.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Multivariate Models en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by