linear fit in Log Scale + extension

Hello, also this question might be trivial and frequently answered, but yet again I'm not able to grasp it. Long story short, that's what I got:
ind = f>=5000& f <= 10000
p = polyfit(f(ind),qU(ind),1);
t = polyval(p,(f(ind)));
plot(f(ind),t,'-r','Linewidth',3);
actually this looks like a straight line to me, even if I set:
set(gca,'XScale','log')
set(gca,'YScale','log')
However I want to extend this line, lets say to [5000 15000]. How can I finally achieve this? Thx in advance

 Respuesta aceptada

David Hill
David Hill el 16 de Jun. de 2020
Editada: David Hill el 16 de Jun. de 2020
ind = f>=5000& f <= 10000
p = polyfit(f(ind),qU(ind),1);%you will always get a line if degree is 1
x=5000:15000;
t = polyval(p,x);
plot(x,t,'-r','Linewidth',3);

3 comentarios

Niklas Kurz
Niklas Kurz el 16 de Jun. de 2020
Thank you for your answere, the extansion works quite well. However my problem seems to be more ravelled. I attached the curve I'm editing, I hope that's sufficient. So basically What I'm trying to do is to fit a line through the first two points and extend it and fit a line through the other points and extend it. In Log Scale it seems to be undefined (0).
Niklas Kurz
Niklas Kurz el 16 de Jun. de 2020
Editada: Niklas Kurz el 16 de Jun. de 2020
so in comparision: Linear scale with Lines
p1 = polyfit(f(1:2),qU(1:2),1);%however many points you want
p2 = polyfit(f(3:end),qU(3:end),1);%second line
x=5000:15000;
t1 = polyval(p1,x);
t2 = polyval(p2,x);
plot(x,t1,'-r',x,t2,'-g','Linewidth',3);

Iniciar sesión para comentar.

Más respuestas (1)

Niklas Kurz
Niklas Kurz el 17 de Jun. de 2020
Thank you for your effort, that is what I implemeted:
p1 = polyfit(f(1:2),qU(1:2),1);%however many points you want
x=5000:50000;
t1 = polyval(p1,x);
plot(x,t1,'-r','Linewidth',3);
p2 = polyfit(f(3:8),qU(3:8),1);%second line
x=15000:640000;
t2 = polyval(p2,x);
plot(x,t2,'-g','Linewidth',3);
However: that is what I receive: Sorry for bothering you still, but its not quite running well due to my lack of log-knowledge.

1 comentario

Okay, I finally unravelled he solution, it proved to be a really tricky one:
p1 = polyfit(log(f(1:2)),log(qU(1:2)),1);%however many points you want
x=5000:50000;
t1 = polyval(p1,log(x));
hold on
loglog(x,exp(t1))
p2 = polyfit(log(f(3:8)),log(qU(3:8)),1);%however many points you want
x=5000:640000;
t2 = polyval(p2,log(x));
hold on
loglog(x,exp(t2))
I view you answere as correct bc your extension was really valuable. Many thanks.

Iniciar sesión para comentar.

Categorías

Productos

Versión

R2020a

Preguntada:

el 16 de Jun. de 2020

Comentada:

el 17 de Jun. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by