diff scripts/polynomial/polyfit.m @ 9138:436b498b0506

simplify polyfit
author Jaroslav Hajek <highegg@gmail.com>
date Mon, 20 Apr 2009 11:45:00 +0200
parents eb63fbe60fab
children 16f53d29049f
line wrap: on
line diff
--- 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)