What is happening with the line of best fit here?
조회 수: 1 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
채택된 답변
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)
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Stress and Strain에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!