Best fit line for log scale Y-axis and linear X-axis. I also want to extrapolate this line.
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
alsa
am 7 Mär. 2018
Bearbeitet: David Goodmanson
am 19 Mär. 2018
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/171055/image.jpeg)
I want to plot 'life' (in log scale) vs E in linear (x-axis) and then extrapolate this until E=3. Below is my current code. The points are fine, but the line is curved instead. The best line should be straight and so the extrapolation would also get a higher Y axis value.
{ life = [p10(1); p9_7(1); p9_4(1); p9_1(1); p8_6(1); p8_3(1); p8_0(1)];
E = [10; 9.7; 9.4; 9.1; 8.6; 8.3; 8.0];
figure;
coef_fit = polyfit(E,life,1);
xi = linspace(3,10,100);
yi = polyval(coef_fit,xi);
plot(E,life,'x',xi,yi, '--');
ax=gca;
ax.YScale='log'; }
0 Kommentare
Akzeptierte Antwort
David Goodmanson
am 8 Mär. 2018
Hello Tsalsabilla
'life' is proportional to exp(-E), meaning that log(life) is proportional to E. E and log(life) have a linear relationship, so E vs. log(life) is what you want to do the polyfit on. After you fit log(life), you exponentiate it to get back to 'life', as follows.
E = [10; 9.7; 9.4; 9.1; 8.6; 8.3; 8.0];
life = flip([53; 40; 20; 1.7;.48; .15; .06]); % estimates off of the plot
loglife = log(life);
coef_fit = polyfit(E,loglife,1);
xi = linspace(3,10,100);
loglife_fit = polyval(coef_fit,xi);
semilogy(E,life,'x',xi,exp(loglife_fit),'--')
However, once you have the plot, you will see how dangerous it is to extrapolate all the way down to E = 3. A small difference in the slope of the fit line is going to make a very large difference in the predicted lifetime.
2 Kommentare
David Goodmanson
am 19 Mär. 2018
Bearbeitet: David Goodmanson
am 19 Mär. 2018
Hi alsa, not so obvious. Easy enough to make the required vectors of upper and lower values for the error bars, 1.05*life and life/1.05. Then see
https://www.mathworks.com/matlabcentral/answers/324880-how-to-add-error-bars-to-a-semilogy-plot#answer_254732
for a solution.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Linear and Nonlinear Regression finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!