필터 지우기
필터 지우기

How to find the variable that minimize the root mean squared error between a known vetor and the multiplication of this variable and an another known vector?

조회 수: 9 (최근 30일)
Supposing that I have a variable , and two known vectors , where N is a known number. I want to find the a that minimizes the root mean squared error between and . Is there any neat apprach to implement it?

채택된 답변

Amal Raj
Amal Raj 2023년 2월 9일
Hi 奥 刘,
You can use linear regression to find a.
Please refer this example below:
N = 100; % Example value for N
x = linspace(0, 10, N)'; % Known vector x
y = sin(x) + 0.1 * randn(N, 1); % Known vector y
X = [ones(N, 1) x]; % Design matrix
a = X \ y; % Solve for a using least squares
y_pred = X * a; % Calculate predicted values of y
rmse = sqrt(mean((y - y_pred) .^ 2)); % Calculate RMSE
  댓글 수: 3
Torsten
Torsten 2023년 2월 9일
편집: Torsten 2023년 2월 9일
You mustn't include the constant term in the calculation of the regression coefficients because you are to regress
y = a*x
not
y = a*x + b
The results for "a" will differ for the two cases.
奥 刘
奥 刘 2023년 2월 10일
@Torsten Yes, that's right. I think @Amal Raj just gave me an example but didn't mean that I should include the constant. Anyway, thanks for reminding me!

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

추가 답변 (1개)

Torsten
Torsten 2023년 2월 9일
a = (c.'*b)/(b.'*b)
where b and c are your column vectors.

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by