Finding Linear regression equation

조회 수: 57 (최근 30일)
HAAAAH
HAAAAH 2019년 9월 11일
답변: Bruno Luong 2019년 9월 11일
I have table of data
x = [65 65 62 67 69 65 61 67]
y = [105 125 110 120 140 135 95 130]
How can i find the equation y = mx+b of linear regression. I have tried so far but dont know how to find m and b ?
x = [65 65 62 67 69 65 61 67]
y = [105 125 110 120 140 135 95 130]
plot (x,y, 'r*')
lsline
% determine how many samples do we have
N= length(x)
% Fit to f(x) = b + m*x
X = [ones [N,1] x]
b = mldivide(X,y)

답변 (2개)

Bruno Luong
Bruno Luong 2019년 9월 11일
P=polyfit(x,y,1);
m=P(1),
b=P(2),
% linefit = polyval(P,x)

Torsten
Torsten 2019년 9월 11일
편집: Torsten 2019년 9월 11일
x = [65 65 62 67 69 65 61 67];
y = [105 125 110 120 140 135 95 130];
X = [ones(numel(x),1),x.'];
p = X\(y.');
b = p(1)
m = p(2)

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by