Least squares regression to find coefficients

์กฐํšŒ ์ˆ˜: 1 (์ตœ๊ทผ 30์ผ)
Tyler Bodnarik
Tyler Bodnarik 2020๋…„ 9์›” 15์ผ
๋‹ต๋ณ€: Asad (Mehrzad) Khoddam 2020๋…„ 9์›” 15์ผ
Not sure what to do here. I tried doing it all seperately by setting noise to 0, then to 50, then 100 and using polyfit but I get the same answer everytime. I also tried using the backslash.
y(๐‘ฅ)=๐‘1+๐‘2๐‘ฅ
where
x = 0:0.1:20;
noise =?? % a number, to define
y= 4*x + noise*rand(1,length(x));
Vary the value for noise as 0, 50 and 100 to get three different results for ๐‘1and ๐‘2,
From a linear algebra standpoint, determine the coefficients, ๐‘1and ๐‘2, of the least-squares-regression of a line fit through the data defined above.

๋‹ต๋ณ€ (1๊ฐœ)

Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam 2020๋…„ 9์›” 15์ผ
one solution is:
[length(x) sum(x); sum(x) sum(x.^2)]\[sum(y) ; sum(x.*y)]

์นดํ…Œ๊ณ ๋ฆฌ

Help Center ๋ฐ File Exchange์—์„œ Linear Regression์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ธฐ

ํƒœ๊ทธ

Community Treasure Hunt

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

Start Hunting!

Translated by