Confusing about applying weighted least square for constant fitting

조회 수: 1 (최근 30일)
WeiHao Xu
WeiHao Xu 2021년 7월 19일
댓글: Matt J 2021년 7월 19일
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

채택된 답변

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

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

추가 답변 (1개)

Torsten
Torsten 2021년 7월 19일
편집: Torsten 2021년 7월 19일
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

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

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by