Mercurial > hg > octave-terminal
changeset 3061:1a5fe3010f09
[project @ 1997-06-25 18:36:19 by jwe]
author | jwe |
---|---|
date | Wed, 25 Jun 1997 18:37:30 +0000 |
parents | 9c6cd52f3f5a |
children | 7310b801f8c2 |
files | scripts/ChangeLog scripts/control/dlqr.m scripts/polynomial/polyfit.m |
diffstat | 3 files changed, 28 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,12 @@ +Wed Jun 25 13:34:06 1997 John W. Eaton <jwe@bevo.che.wisc.edu> + + * polynomial/polyfit.m: Return fit y values as second output. + Don't use QR factorization to solve least squares problem. + +Wed Jun 18 10:24:00 1997 John W. Eaton <jwe@bevo.che.wisc.edu> + + * control/dlqr.m: Use ao, not a, to compute k. + Tue Jun 3 12:16:00 1997 John W. Eaton <jwe@bevo.che.wisc.edu> * miscellaneous/path.m: New file.
--- a/scripts/control/dlqr.m +++ b/scripts/control/dlqr.m @@ -92,7 +92,7 @@ if (is_symmetric (q) && is_symmetric (r) ... && all (eig (q) >= 0) && all (eig (r) > 0)) p = dare (ao, b, qo, r); - k = (r+b'*p*b)\b'*p*a + r\zz'; + k = (r+b'*p*b)\b'*p*ao + r\zz'; e = eig (a - b*k); else error ("dlqr: q (r) must be symmetric positive (semi) definite");
--- a/scripts/polynomial/polyfit.m +++ b/scripts/polynomial/polyfit.m @@ -17,17 +17,20 @@ ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA ## 02111-1307, USA. -## usage: polyfit (x, y, n) +## usage: [p, yf] = polyfit (x, y, n) ## ## Returns the coefficients of a polynomial p(x) of degree n that ## minimizes sumsq (p(x(i)) - y(i)), i.e., that best fits the data ## in the least squares sense. +## +## If two outputs are requested, also return the values of the +## polynomial for each value of x. ## Author: KH <Kurt.Hornik@ci.tuwien.ac.at> ## Created: 13 December 1994 ## Adapted-By: jwe -function p = polyfit (x, y, n) +function [p, yf] = polyfit (x, y, n) if (nargin != 3) @@ -46,22 +49,26 @@ x = reshape (x, l, 1); y = reshape (y, l, 1); - X = ones (l, 1); + ## Unfortunately, the economy QR factorization doesn't really save + ## memory doing the computation -- the returned values are just + ## smaller. - if (n > 0) - tmp = (x * ones (1, n)) .^ (ones (l, 1) * (1 : n)); - X = [X, tmp]; - endif + ## [Q, R] = qr (X, 0); + ## p = flipud (R \ (Q' * y)); - ## Compute polynomial coeffients, making returned value compatible - ## with Matlab. + ## XXX FIXME XXX -- this is probably not so good for extreme values of + ## N or X... - [Q, R] = qr (X, 0); + X = (x * ones (1, n+1)) .^ (ones (l, 1) * (0 : n)); - p = flipud (R \ (Q' * y)); + p = (X' * X) \ (X' * y); if (! prefer_column_vectors) p = p'; endif + if (nargout == 2) + yf = X * p; + endif + endfunction