How can I extend polyfit line on loglog scale ?

7 visualizaciones (últimos 30 días)
A. Panton
A. Panton el 6 de En. de 2022
Comentada: Bjorn Gustavsson el 6 de En. de 2022
I wrote this code, but I need to extend this line from y=10 to y=100. I tried but I couldn't do it. Can anybody help ?
x= [0.310 0.220 0.125 0.065]
y= [95.4 63.3 36.8 22.4]
X=log10(x); Y=log10(y);
P=polyfit(X,Y,1);
yhat=10.^[polyval(P,[X(1) X(end)])];
loglog(x,y,'s')
hold on
loglog([x(1) x(end)],yhat)
xlabel('(mm)')
ylabel('(%)')
grid on
slope = P(1)
txt = ['m=' num2str(P(1))]
text(0.4,40,txt)

Respuesta aceptada

Bjorn Gustavsson
Bjorn Gustavsson el 6 de En. de 2022
When you calculate yhat you only do that for the first and last element of your x-values that you use for the fit. You should try to extend the range of x-values and calculate yhat-values for a larger range. Something like this might help you on your way:
x= [0.310 0.220 0.125 0.065]
y= [95.4 63.3 36.8 22.4]
X=log10(x); Y=log10(y);
P=polyfit(X,Y,1);
Xi = log10(linspace(min(x)/10,max(x)*10),101); % New variable to use for the evaluation of the fit
yhat=10.^[polyval(P,Xi)];
loglog(x,y,'s')
hold on
loglog(10.^Xi,yhat) % Modified plotting.
xlabel('(mm)')
ylabel('(%)')
grid on
slope = P(1)
txt = ['m=' num2str(P(1))]
text(0.4,40,txt)
From that you might need to adjust the Xi-variable and zoom in the plot.
HTH
  2 comentarios
A. Panton
A. Panton el 6 de En. de 2022
Thank you very much, but the log10 line gives an error I think it should be like this
Xi = log10(linspace(min(x)/10,max(x)*10,101)); % New variable to use for the evaluation of the fit
Bjorn Gustavsson
Bjorn Gustavsson el 6 de En. de 2022
Yes, I goofed...

Iniciar sesión para comentar.

Más respuestas (0)

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