Mercurial > hg > octave-lyh
diff scripts/polynomial/polyfit.m @ 3091:b06dcbb6b3b1
[project @ 1997-10-10 16:26:47 by jwe]
author | jwe |
---|---|
date | Fri, 10 Oct 1997 16:26:48 +0000 |
parents | db6d57d718f7 |
children | 4bb976b250bf |
line wrap: on
line diff
--- a/scripts/polynomial/polyfit.m +++ b/scripts/polynomial/polyfit.m @@ -1,4 +1,4 @@ -## Copyright (C) 1996, 1997 John W. Eaton +## Copyright (C) 1996 John W. Eaton ## ## This file is part of Octave. ## @@ -45,6 +45,8 @@ error ("polyfit: n must be a nonnegative integer"); endif + y_is_row_vector = (rows (y) == 1); + l = length (x); x = reshape (x, l, 1); y = reshape (y, l, 1); @@ -61,14 +63,20 @@ X = (x * ones (1, n+1)) .^ (ones (l, 1) * (0 : n)); - p = flipud ((X' * X) \ (X' * y)); + p = (X' * X) \ (X' * y); + + if (nargout == 2) + yf = X * p; + endif + + p = flipud (p); if (! prefer_column_vectors) p = p'; endif - if (nargout == 2) - yf = X * p; + if (y_is_row_vector) + yf = yf'; endif endfunction