How to make the line of best fit go through the origin?

조회 수: 21 (최근 30일)
Ash Maxwell
Ash Maxwell 2020년 4월 23일
댓글: Mohd Aaquib Khan 2023년 9월 13일
Effectivenormalstress=[41,79,119,159,197,80];
Maximumshearstress=[34,73,97,138,173,56];
x=Effectivenormalstress;
y=Maximumshearstress;
scatter(x, y, 'rx');
xlabel('Effective normal stress');
ylabel('Shear stress');
sgtitle('Interpretation for angles of shearing resistance');
coefficients=polyfit(x, y, 1);
xFit=linspace(min(x),max(x),1000);
yFit=polyval(coefficients, xFit);
hold on;
plot(xFit,yFit,'b-' , 'LineWidth',1);
grid on;

채택된 답변

David Goodmanson
David Goodmanson 2020년 4월 23일
편집: David Goodmanson 2020년 4월 23일
Hello Ash,
Effectivenormalstress=[41,79,119,159,197,80]'; % make these into column vectors
Maximumshearstress=[34,73,97,138,173,56]';
x=Effectivenormalstress;
y=Maximumshearstress;
c = x\y
xplot = 1:200;
plot(xplot,c*xplot,x,y,'o');grid on
The idea is to fit the linear relation x*c = y in the least squares sense where x and y are column vectors.
  댓글 수: 1
Mohd Aaquib Khan
Mohd Aaquib Khan 2023년 9월 13일
Hi David, this is very useful, thanks.
Also how can I find the goodness of fit in this fit? R value or any other goodness of fit parameter!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by