Borrar filtros
Borrar filtros

Best fitting curve for variable data

1 visualización (últimos 30 días)
Somnath Kale
Somnath Kale el 23 de Abr. de 2022
Editada: Matt J el 23 de Abr. de 2022
Hello
I was trying fitting to fit the following data
x = 1.0779 1.2727 1.4700 1.5766 1.6471 1.7396 1.7828 1.8208 1.8370
y = 7.9511 9.8400 12.8838 15.1925 31.0055 36.0292 62.5528 87.9648 176.4142
for the equation:
y = a exp(b*(1/x)^c)
where a ba nd c are fitting paramters.
I triesd the fiting but unfortinately i was not able to magae it. It will be really helpful experties can guide me in this context.
Thanks in advance!

Respuesta aceptada

Matt J
Matt J el 23 de Abr. de 2022
Editada: Matt J el 23 de Abr. de 2022
Using fminspleas from the File Exchange
% data
x = [1.0779 1.2727 1.4700 1.5766 1.6471 1.7396 1.7828 1.8208 1.8370]' ;
y = [7.9511 9.8400 12.8838 15.1925 31.0055 36.0292 62.5528 87.9648 176.4142]' ; ;
funlist={1,@(c,xx) (1./xx).^c};
[c,ab]= fminspleas(funlist,-3,x,log(y),-inf,0);
a=exp(ab(1));
b=ab(2);
a,b,c
a = 8.6541
b = 0.0088
c = -9.4295
xx=linspace(min(x),max(x),100);
fun=@(x)a*exp(b*(1./x).^c);
plot(x,y,'o',xx,fun(xx))
ylim([0,max(y)])

Más respuestas (1)

KSSV
KSSV el 23 de Abr. de 2022
Editada: KSSV el 23 de Abr. de 2022
% data
x = [1.0779 1.2727 1.4700 1.5766 1.6471 1.7396 1.7828 1.8208 1.8370]' ;
y = [7.9511 9.8400 12.8838 15.1925 31.0055 36.0292 62.5528 87.9648 176.4142]' ; ;
eqn = @(a,b,c,x) a*exp(b*(1./x).^c) ; % equation to fit
% Define Start points
x0 = [1 1 1];
% fit-function
fitfun = fittype(eqn);
% fit curve
[fitted_curve,gof] = fit(x,y,fitfun,'StartPoint',x0)
fitted_curve =
General model: fitted_curve(x) = a*exp(b*(1./x).^c) Coefficients (with 95% confidence bounds): a = 15.61 (1.495, 29.73) b = 1.14e-06 (-1.433e-05, 1.661e-05) c = -23.93 (-46.14, -1.715)
gof = struct with fields:
sse: 879.6251 rsquare: 0.9635 dfe: 6 adjrsquare: 0.9513 rmse: 12.1080
% Save the coeffiecient values for a,b,c
coeffvals = coeffvalues(fitted_curve);
% Plot results
scatter(x, y, 'bs')
hold on
plot(x,fitted_curve(x),'r')
legend('data','fitted curve')
  3 comentarios
KSSV
KSSV el 23 de Abr. de 2022
You have the code... Go ahead.
Somnath Kale
Somnath Kale el 23 de Abr. de 2022
Editada: Somnath Kale el 23 de Abr. de 2022
I tried using your code but did not get the expected results for fitting parameters
I have wrote following code uning diffenrt function fminsearch:
% fitting
x = [0.0970 0.1190 0.1323 0.1419 0.1515 0.1566 0.1605 0.1639 0.1653]';
y = [7.9511 9.8400 12.8838 15.1925 31.0055 36.0292 62.5528 87.9648 176.4142]';
semilogy(1./x,y,'o')
f = @(a,b,c,x) a*exp((b./x).^c);
obj_fun = @(params) norm(f(params(1), params(2), params(3), x) -y);
sol = fminsearch(obj_fun, [1,10,1]);
a = sol(1)
b = sol(2)
c = sol(3)
hold on
semilogy(1./x,f(sol(1),sol(2),sol(3),x),'-')
hold off
ylabel('y')
xlabel('1/x')
but im getting following issue:
Exiting: Maximum number of function evaluations has been exceeded
- increase MaxFunEvals option.
Current function value: 103.027992
how take care of this one?

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by