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?
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1289910/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1289915/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1289920/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1289925/image.png)
0 commentaires
Réponse acceptée
Amal Raj
le 9 Fév 2023
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
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Descriptive Statistics dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!