Curve fitting with loglog data

12 visualizaciones (últimos 30 días)
Manny Kins
Manny Kins el 6 de Ag. de 2021
Comentada: Star Strider el 9 de Ag. de 2021
I am having some issues fitting a curve using polyfit to log data. I think I am making a silly mistake during the fit plotting as the fitting is really bad during the beggining but can't seem to figure it out. Any help would be greatly appreciated! I have attached the data as: msd_help
load('msd_help')
figure()
loglog(s,m)
hold on
linearCoefficients = polyfit((s),(m), 1);
yFit = polyval(linearCoefficients, s);
loglog(s, yFit, 'r-', 'LineWidth', 2)
  1 comentario
Yazan
Yazan el 6 de Ag. de 2021
Editada: Yazan el 6 de Ag. de 2021
You are not doing anything wrong, and the fitting is working. However, you are plotting the results using a base 10 logarithmic scale. See below the same result plotted using a linear scale.

Iniciar sesión para comentar.

Respuesta aceptada

Star Strider
Star Strider el 6 de Ag. de 2021
Fit it to a power function:
LD = load('msd_help.mat');
m = LD.m;
s = LD.s;
fcn = @(b,x) x.^b(1).*exp(b(2));
B = fminsearch(@(b) norm(m - fcn(b,s)), rand(2,1))
yFit = fcn(B,s);
figure
loglog(s,m,'.')
hold on
plot(s, yFit,'-r')
hold off
grid
producing:
B =
0.867368600071621
-27.933653082691194
and:
.
  6 comentarios
Manny Kins
Manny Kins el 9 de Ag. de 2021
Thanks for your help and insight
Star Strider
Star Strider el 9 de Ag. de 2021
As always, my pleasure!
.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by