Least squares regression to find coefficients
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
Asad (Mehrzad) Khoddam
2020-9-15
one solution is:
[length(x) sum(x); sum(x) sum(x.^2)]\[sum(y) ; sum(x.*y)]
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!