polyfit: add a third output argument, mu [PATCH]

View: New views
1 Messages — Rating Filter:   Alert me  

polyfit: add a third output argument, mu [PATCH]

by Shaun Jackman-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The following patch adds a third output argument, mu for compatibility with
Matlab. I made a best effort at the documentation update, but I'm not familiar
with Octave's documentation system.

Cheers,
Shaun

2008-06-30  Shaun Jackman  <sjackman@...>

        * polynomial/polyfit.m (polyfit): Add a third output argument,
        mu, for compatibility. If three output arguments are requested,
        the input argument x is shifted and scaled before fitting.

--- /opt/octave-3.0.1/share/octave/3.0.1/m/polynomial/polyfit.m.orig 2008-04-25
09:17:07.000000000 -0700
+++ /opt/octave-3.0.1/share/octave/3.0.1/m/polynomial/polyfit.m 2008-06-30
11:15:46.000000000 -0700
@@ -51,6 +51,10 @@
  ## @item yf
  ## The values of the polynomial for each value of @var{x}.
  ## @end table
+##
+## If three output arguments are requested, the input argument @var{x}
+## is transformed before fitting by @code{(x - mu(1)) / mu(2)},
+## where @code{mu(1) = mean(x)} and @code{mu(2) = std(x)}.
  ## @end deftypefn

  ## Author: KH <Kurt.Hornik@...>
@@ -72,6 +76,12 @@
      error ("polyfit: n must be a nonnegative integer");
    endif

+  if (nargout > 2)
+  mu(1) = mean(x);
+  mu(2) = std(x);
+  x = (x - mu(1)) / mu(2);
+  endif
+
    y_is_row_vector = (rows (y) == 1);

    l = length (x);
_______________________________________________
Bug-octave mailing list
Bug-octave@...
https://www.cae.wisc.edu/mailman/listinfo/bug-octave