changeset 2538:6f71af650490

[project @ 1996-11-19 21:41:48 by jwe]
author jwe
date Tue, 19 Nov 1996 21:44:36 +0000
parents 80b982e7f4b1
children 1dca28c213f0
files doc/interpreter/arith.texi doc/interpreter/signal.texi scripts/miscellaneous/bincoeff.m scripts/miscellaneous/xor.m
diffstat 4 files changed, 171 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/doc/interpreter/arith.texi	Tue Nov 19 21:15:07 1996 +0000
+++ b/doc/interpreter/arith.texi	Tue Nov 19 21:44:36 1996 +0000
@@ -115,14 +115,46 @@
 see @ref{Linear Algebra}.
 @end deftypefn
 
-@deftypefn {Mapping Function} {} log2 (@var{x})
-Compute the base-2 logarithm of @var{x}.
+@deftypefn {Mapping Function} {@var{y} =} log2 (@var{x})
+@deftypefnx {Mapping Function} {[@var{f}, @var{e}]} log2 (@var{x})
+Compute the base-2 logarithm of @var{x}.  With two outputs, returns
+@var{f} and @var{e} such that
+@iftex
+@tex
+ $1/2 <= |f| < 1$ and $x = f * 2^e$.
+@end tex
+@end iftex
+@ifinfo
+ 1/2 <= abs(f) < 1 and x = f * 2^e.
+@end ifinfo
 @end deftypefn
 
 @deftypefn {Mapping Function} {} log10 (@var{x})
 Compute the base-10 logarithm of @var{x}.
 @end deftypefn
 
+@deftypefn {Mapping Function} {} pow2 (@var{x})
+@deftypefnx {Mapping Function} {} pow2 (@var{f}, @var{e})
+With one argument, computes
+@iftex
+@tex
+ $2^x$
+@end tex
+@end iftex
+@ifinfo
+ 2 .^ x
+@end ifinfo
+for each element of @var{x}.  With two arguments, returns
+@iftex
+@tex
+ $f 2^e$.
+@end tex
+@end iftex
+@ifinfo
+ f .* (2 .^ e).
+@end ifinfo
+@end deftypefn
+
 @deftypefn {Mapping Function} {} sqrt (@var{x})
 Compute the square root of @var{x}.  To compute the matrix square root,
 see @ref{Linear Algebra}.
@@ -159,6 +191,13 @@
 agree, or if either of the arguments is complex.
 @end deftypefn
 
+@deftypefn {Mapping Function} {} xor (@var{x}, @var{y})
+Return the `exclusive or' of the entries of @var{x} and @var{y}.
+For boolean expressions @var{x} and @var{y},
+@code{xor (@var{x}, @var{y})} is true if and only if either @var{x} or
+@var{y} is true.
+@end deftypefn
+
 @node Complex Arithmetic, Trigonometry, Utility Functions, Arithmetic
 @section Complex Arithmetic
 
@@ -344,6 +383,10 @@
 compatible dimensions.
 @end deftypefn
 
+@deftypefn {Mapping Function} {} bincoeff (@var{n}, @var{k})
+Returns the binomial coefficient of @var{n} and @var{k}.
+@end deftypefn
+
 @deftypefn {Mapping Function} {} erf (@var{z})
 Computes the error function,
 @iftex
@@ -369,10 +412,9 @@
 Computes the complementary error function, @code{1 - erf (@var{z})}.
 @end deftypefn
 
-@c XXX FIXME XXX -- this isn't actually distributed with Octave yet.
-@c
-@c @item erfinv
-@c Computes the inverse of the error function.
+@deftypefn {Mapping Function} {} erfinv (@var{z})
+Computes the inverse of the error function.
+@end deftypefn
 
 @deftypefn {Mapping Function} {} gamma (@var{z})
 Computes the Gamma function,
--- a/doc/interpreter/signal.texi	Tue Nov 19 21:15:07 1996 +0000
+++ b/doc/interpreter/signal.texi	Tue Nov 19 21:44:36 1996 +0000
@@ -9,6 +9,17 @@
 functions.  If you would like to help improve Octave in this area,
 please contact @code{bug-octave@@bevo.che.wisc.edu}.
 
+@deftypefn {Function File} {} detrend (@var{x}, @var{p})
+If @var{x} is a vector, @code{detrend (@var{x}, @var{p})} removes the
+best fit of a polynomial of order @var{p} from the data @var{x}.
+
+If @var{x} is a matrix, @code{detrend (@var{x}, @var{p})} does the same
+for each column in @var{x}.
+
+The second argument is optional.  If it is not specified, a value of 1
+is assumed.  This corresponds to removing a linear trend.
+@end deftypefn
+
 @deftypefn {Function} {} fft (@var{a} [, @var{n}])
 Compute the FFT of @var{a} using subroutines from FFTPACK.  If @var{a}
 is a matrix, @code{fft} computes the FFT for each column of @var{a}.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/miscellaneous/bincoeff.m	Tue Nov 19 21:44:36 1996 +0000
@@ -0,0 +1,73 @@
+## Copyright (C) 1995, 1996  Kurt Hornik
+## 
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2, or (at your option)
+## any later version.
+## 
+## This program is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details. 
+## 
+## You should have received a copy of the GNU General Public License
+## along with this file.  If not, write to the Free Software Foundation,
+## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+## usage:  bincoeff (n, k)
+##
+## Returns the binomial coefficient of n and k.
+
+## Author: KH <Kurt.Hornik@ci.tuwien.ac.at>
+## Created: 8 October 1994
+## Adapted-By: jwe
+
+function b = bincoeff (n, k)
+  
+  if (nargin != 2)
+    usage ("bincoeff (n, k)");
+  endif
+  
+  [retval, n, k] = common_size (n, k);
+  if (retval > 0)
+    error ("bincoeff:  n and k must be of common size or scalars");
+  endif
+  
+  [r, c] = size (n);
+  s = r * c;
+  n   = reshape (n, s, 1);
+  k   = reshape (k, s, 1);
+  b   = zeros (s, 1);
+  
+  ind = find (! (k >= 0) | (k != real (round (k))) | isnan (n));
+  if (any (ind))
+    b(ind) = NaN * ones (length (ind), 1);
+  endif
+  
+  ind = find (k == 0);
+  if (any (ind))
+    b(ind) = ones (length (ind), 1);
+  endif
+
+  ind = find ((k > 0) & ((n == real (round (n))) & (n < 0)));
+  if any (ind)
+    b(ind) = (-1) .^ k(ind) .* exp (lgamma (abs (n(ind)) + k(ind)) ...
+	- lgamma (k(ind) + 1) - lgamma (abs (n(ind))));
+  endif
+  
+  ind = find ((k > 0) & ((n != real (round (n))) | (n >= k)));
+  if (length (ind) > 0)
+    b(ind) = exp (lgamma (n(ind) + 1) - lgamma (k(ind) + 1) ...
+	- lgamma (n(ind) - k(ind) + 1));
+  endif
+  
+  ## clean up rounding errors
+  ind = find (n == round (n));
+  if (any (ind))
+    b(ind) = round (b(ind));
+  endif
+  
+  b = reshape (b, r, c);
+  
+endfunction
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/miscellaneous/xor.m	Tue Nov 19 21:44:36 1996 +0000
@@ -0,0 +1,39 @@
+## Copyright (C) 1995, 1996  Kurt Hornik
+## 
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2, or (at your option)
+## any later version.
+## 
+## This program is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details. 
+## 
+## You should have received a copy of the GNU General Public License
+## along with this file.  If not, write to the Free Software Foundation,
+## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+## usage:  xor (x, y)
+##
+## Returns the "exclusive or" of the entries of x and y.
+## For boolean expressions x and y, xor (x, y) is true iff either x
+## or y is true.
+
+## Author: KH <Kurt.Hornik@ci.tuwien.ac.at>
+## Created: 16 September 1994
+## Adapted-By: jwe
+
+function z = xor (x, y)
+
+  if (nargin != 2)
+    usage ("xor (x, y)");
+  endif
+
+  if (is_scalar (x) || is_scalar (y) || size (x) == size (y))  
+    error ("xor: x and y must be of common size or scalars");
+  endif
+  
+  z = (x | y) - (x & y);
+  
+endfunction