Mercurial > hg > octave-max
changeset 9138:436b498b0506
simplify polyfit
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 20 Apr 2009 11:45:00 +0200 |
parents | eebc7f8e7398 |
children | 829724a7f5f3 |
files | scripts/polynomial/polyfit.m |
diffstat | 1 files changed, 4 insertions(+), 4 deletions(-) [+] |
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)