Turing a Least Squares function into a Weighted Least Squares
Ältere Kommentare anzeigen
So i originally wrote my function for a least squared function but it turns out I need to write my function to figure out the weighted least squares. From my understanding, a weighted least squares problem can be solved by the basic least squares method after we multiply both Yi and the ith row of X by wi in a typical equation. But how do I should this in a matlab function?
function [A, e] = WeightedLeastSquares(X, Y, w) size(A) rank(A) rank([A b]) X = A\b Y = norm(A*X) w = pinv(A)*b
I already have the variables A,e, X,Y,w loaded onto my current workspace, but I just need to change my function. So, if I call,
load Lab08Data.mat
I get
[A, e] = WeightedLeastSquares(X3, Y3, w)
A =
3.0573
1.9250
e =
0.0218
-0.0702
0.3235
0.0552
-0.1038
-0.0202
Any suggestions on how turn my function to a weighted least squares function?
3 Kommentare
SB
am 26 Okt. 2012
Hey, I'm stuck on the same question! How did you get the original least squares polynomial regression btw? I tried function [A,e] = MyPolyRegressor(x, y, n)
for i = 1:n
b(i) = x(i)^(n-i) ;
end
A=b\y'
e=b*A-y'
But it didn't work.
Ben
am 26 Okt. 2012
SB
am 26 Okt. 2012
I dont think we're allowed to use polyfit; it defeats the purpose of the problem.
Antworten (0)
Kategorien
Mehr zu Mathematics finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!