フィルターのクリア

How can I find the coeficients alpha, beta of the simple linear regression, using "\" operator

2 ビュー (過去 30 日間)
Ihor
Ihor 2022 年 12 月 10 日
編集済み: Torsten 2022 年 12 月 11 日
How can I find the coeficients alpha, beta for the X coordinates of the simple linear regression, using "\" operator?

回答 (1 件)

Torsten
Torsten 2022 年 12 月 10 日
x = (0:0.1:1).';
y = 3*x + 4 + 0.01*randn(numel(x),1);
A = [x,ones(size(x))];
b = y;
coeffs = A\b;
coeffs(1)
ans = 3.0072
coeffs(2)
ans = 3.9919
  2 件のコメント
Ihor
Ihor 2022 年 12 月 11 日
Thank you! What does it mean?:
A = [x,ones(size(x))];
I know that will be a matrix, but what does it do?
Torsten
Torsten 2022 年 12 月 11 日
編集済み: Torsten 2022 年 12 月 11 日
You want to solve
x(1)*a + 1*b = y(1)
x(2)*a + 1*b = y(2)
...
x(end)*a + 1*b = y(end)
for a and b.
If you write this in matrix form M*[a;b] = v, you get the above M and v (I named them A and b), and you solve for [a;b] as
ab = M\v.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLinear and Nonlinear Regression についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by