How to create a best fit line here?

5 ビュー (過去 30 日間)
Zifeng Qiu
Zifeng Qiu 2021 年 2 月 10 日
コメント済み: Zifeng Qiu 2021 年 2 月 10 日
I was trying to make a best-fit line with the data that I have, but for some reason the polyfit command doesn't seem to give me the right answer for it. Does anyone know how to fix it? Thank you.
thickness = 0.8; % the units are in mm
width = 12.7;
area = thickness*width;
load = xlsread('homework1.xlsx','A9:A42');
strain = xlsread('homework1.xlsx','B9:B42');
trueStress1 = (load.*(1+strain))./area; % true stress calculation
trueStrain1 = log(strain + 1); % true strain calculation
x = log(trueStrain1);
y = log(trueStress1);
p = polyfit(x,y,1); % bestfit the line between points
f = polyval(p,x);
figure;
plot(x,y,'o');
hold on
plot(x,f,'-');
title('True Stress vs. True Strain');
xlabel('Log \epsilon');
ylabel('Log \sigma');
legend('data','linear fit','location','northwest')

採用された回答

Chad Greene
Chad Greene 2021 年 2 月 10 日
It looks like the first x value is -Inf. Try eliminating that point from the polynomial fit, like this:
p = polyfit(x(2:end),y(2:end),1); % bestfit the line between points
  1 件のコメント
Zifeng Qiu
Zifeng Qiu 2021 年 2 月 10 日
Thanks, it worked

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStress and Strain についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by