Mercurial > hg > octave-max
changeset 3091:b06dcbb6b3b1
[project @ 1997-10-10 16:26:47 by jwe]
author | jwe |
---|---|
date | Fri, 10 Oct 1997 16:26:48 +0000 |
parents | 63bda47c6512 |
children | 4bb976b250bf |
files | scripts/ChangeLog scripts/polynomial/polyfit.m |
diffstat | 2 files changed, 18 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,9 @@ +Fri Oct 10 11:18:10 1997 John W. Eaton <jwe@bevo.che.wisc.edu> + + * polynomial/polyfit.m: Compute yf correctly. From Seung Lee + <SJL@nrc.gov>. Also return yf in the same orientation as the + original y vector. + Fri Sep 19 17:04:40 1997 John W. Eaton <jwe@bevo.che.wisc.edu> * linear-algebra/cross.m: Use direct formula instead of calling
--- 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