필터 지우기
필터 지우기

Line of best fit

조회 수: 5 (최근 30일)
Kyle Hamanne
Kyle Hamanne 2020년 10월 8일
댓글: Star Strider 2020년 10월 8일
How would i go about adding a line of best fit to this plot?
E = 6.9*10^10;
xaxis = [-20, -11.8, 0.4, 9.4, 20];
stress = [0.00039174, 0.00017886, -2.02e-06, -0.000214, -0.0002926]*E;
stress1 = stress;
plot(xaxis, stress1, 'r', 'Marker', '*')
xlabel('Vertical Distance from Neutral Axis (mm)')
ylabel('Stress (N/mm^2)')
title('Stress data with respect to Neutral axis')
legend('Stress data')

채택된 답변

Star Strider
Star Strider 2020년 10월 8일
It depends on what you intend by ‘best fit’.
For a linear fit, add these lines:
P = polyfit(xaxis, stress, 1);
linfit = polyval(P, xaxis);
hold on
plot(xaxis, linfit, '--b')
hold off
so the complete code si now:
E = 6.9*10^10;
xaxis = [-20, -11.8, 0.4, 9.4, 20];
stress = [0.00039174, 0.00017886, -2.02e-06, -0.000214, -0.0002926]*E;
stress1 = stress;
plot(xaxis, stress1, 'r', 'Marker', '*')
xlabel('Vertical Distance from Neutral Axis (mm)')
ylabel('Stress (N/mm^2)')
title('Stress data with respect to Neutral axis')
legend('Stress data')
P = polyfit(xaxis, stress, 1);
linfit = polyval(P, xaxis);
hold on
plot(xaxis, linfit, '--b')
hold off
For a different fitting function, use a different model, and likely fminsearch rather than polyfit if it is not a polynomial function.
That is your call.
  댓글 수: 2
Kyle Hamanne
Kyle Hamanne 2020년 10월 8일
The linear fit is perfect thankyou!
Star Strider
Star Strider 2020년 10월 8일
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

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

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by