Confusing about applying weighted least square for constant fitting

2 vues (au cours des 30 derniers jours)
WeiHao Xu
WeiHao Xu le 19 Juil 2021
Commenté : Matt J le 19 Juil 2021
I'm now fitting a line with noise. My equation is to minimize corresponding to equation , then I have and with data. I want to caculate the best y. The WSL gives for the answer. But now my confusing is what is Y? Is this , which means my code is
(1) is the matrix with number 1. Is this right for me? or I should use other function such as fminsearch(I saw in the community, maybe it's still my missunderstanding)...Thanks

Réponse acceptée

Matt J
Matt J le 19 Juil 2021
Modifié(e) : Matt J le 19 Juil 2021
I would recommend lscov
p=lscov(x(:).^[1,0],y,w/N);
yfit=polyval(p,x)
  6 commentaires
WeiHao Xu
WeiHao Xu le 19 Juil 2021
Thanks for your helping, I will try it later!
Matt J
Matt J le 19 Juil 2021
You're welcome, but if you find that one of the answers does what you want, please do Accept-click it.

Connectez-vous pour commenter.

Plus de réponses (1)

Torsten
Torsten le 19 Juil 2021
Modifié(e) : Torsten le 19 Juil 2021
X = ones(N,1)
W = diag(w)
Y = y
where y is the (Nx1) column vector of the measurements and w is the (Nx1) column vector of weights.
The result of your formula is the coefficient a of the line y=a that best approximates the measurements.
  5 commentaires
Torsten
Torsten le 19 Juil 2021
Correct.
WeiHao Xu
WeiHao Xu le 19 Juil 2021
Thanks so much!

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by