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!