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?

采纳的回答

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.

更多回答(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