# HG changeset patch # User jwe # Date 876500808 0 # Node ID b06dcbb6b3b106fc70b2607e9103b77c3de3c35b # Parent 63bda47c6512e1164a4d23a360a4be8975b03da5 [project @ 1997-10-10 16:26:47 by jwe] diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,9 @@ +Fri Oct 10 11:18:10 1997 John W. Eaton + + * polynomial/polyfit.m: Compute yf correctly. From Seung Lee + . Also return yf in the same orientation as the + original y vector. + Fri Sep 19 17:04:40 1997 John W. Eaton * linear-algebra/cross.m: Use direct formula instead of calling diff --git a/scripts/polynomial/polyfit.m b/scripts/polynomial/polyfit.m --- 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