What is happening with the line of best fit here?
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
John D'Errico
on 19 Sep 2024
Edited: John D'Errico
on 19 Sep 2024
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.
More Answers (0)
See Also
Categories
Find more on Stress and Strain in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!