# HG changeset patch # User Jaroslav Hajek # Date 1240220700 -7200 # Node ID 436b498b050689039604f011df2eb4abfa45a358 # Parent eebc7f8e739865ceb9134251b5653c40a2584588 simplify polyfit diff --git a/scripts/polynomial/polyfit.m b/scripts/polynomial/polyfit.m --- a/scripts/polynomial/polyfit.m +++ b/scripts/polynomial/polyfit.m @@ -79,15 +79,15 @@ ## Reshape x & y into column vectors. l = numel (x); - x = reshape (x, l, 1); - y = reshape (y, l, 1); + x = x(:); + y = y(:); ## Construct the Vandermonde matrix. - v = (x * ones (1, n+1)) .^ (ones (l, 1) * (n : -1 : 0)); + v = vander (x, n+1); ## Solve by QR decomposition. [q, r, k] = qr (v, 0); - p = r \ (y' * q)'; + p = r \ (q' * y); p(k) = p; if (nargout > 1)