What is happening with the line of best fit here?

조회 수: 1 (최근 30일)
Asher
Asher 2024년 9월 19일
댓글: Asher 2024년 9월 19일
StrainStress = [0.00005 010.1;
0.00007 014.3;
0.00011 021.8;
0.00014 027.6;
0.00020 040.0;
0.00030 061.1;
0.00040 079.8;
0.00055 109.7;
0.00080 154.0;
0.00110 210.9;
0.00160 318.6];
Strain = StrainStress(:,1);
Stress = StrainStress(:,2);
plot(Strain,Stress, 'gs');
xlabel Stress;
ylabel Strain;
hold on;
P = polyfit(Stress,Strain,1);
F = polyval(P,Strain);
plot(Stress,Strain,'gs',Stress,F,'k--');
I am trying to produce a linear line of best fit for a given set of points (Stress and Strain values).
When I go to the graph it seems to be giving me something which I do not understand at all.
Am I using the polyfit function wrong?

채택된 답변

John D'Errico
John D'Errico 2024년 9월 19일
편집: John D'Errico 2024년 9월 19일
StrainStress = [0.00005 010.1;
0.00007 014.3;
0.00011 021.8;
0.00014 027.6;
0.00020 040.0;
0.00030 061.1;
0.00040 079.8;
0.00055 109.7;
0.00080 154.0;
0.00110 210.9;
0.00160 318.6];
Strain = StrainStress(:,1);
Stress = StrainStress(:,2);
plot(Strain,Stress, 'gs');
xlabel Stress;
ylabel Strain;
And that looks like a nicely linear relation. I wish all of my data always looked that good.
Next, you fit the result, of strain as a linear function of stress.
P = polyfit(Stress,Strain,1)
P = 1×2
1.0e-05 * 0.5092 -0.1428
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Fine still.
% F = polyval(P,Strain);
So then why in the name of god and little green apples did you try to use those coefficients, by passing in strain? You passed in the DEPENDENT variable into the polynomial!
I know, you were under a lot of stress when you wrote that line. ;-)
F = polyval(P,Stress);
plot(Stress,Strain,'gs',Stress,F,'k--');
Looks fine now.
  댓글 수: 1
Asher
Asher 2024년 9월 19일
Wonderful thank you! And yes I was under a lot of STRESS :-)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Stress and Strain에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by