annotate scripts/specfun/realpow.m @ 9141:c1fff751b5a8

Update section 17.1 (Utility Functions) of arith.txi Split section into "Exponents and Logarithms" and "Utility Functions" Use Tex in many more of the doc strings for pretty printing in pdf format.
author Rik <rdrider0-list@yahoo.com>
date Mon, 20 Apr 2009 17:16:09 -0700
parents 1bf0ce0930be
children 16f53d29049f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7621
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
1 ## Copyright (C) 2008 David Bateman
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
2 ##
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
3 ## This file is part of Octave.
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
4 ##
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
8 ## your option) any later version.
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
9 ##
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
13 ## General Public License for more details.
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
14 ##
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
18
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
19 ## -*- texinfo -*-
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
20 ## @deftypefn {Function File} {} realpow (@var{x}, @var{y})
9141
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9051
diff changeset
21 ## Compute the real-valued, element-by-element power operator. This is
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9051
diff changeset
22 ## equivalent to @w{@code{@var{x} .^ @var{y}}}, except that @code{realpow}
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9051
diff changeset
23 ## reports an error if any return value is complex.
8286
6f2d95255911 fix @seealso references to point to existing anchors
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7989
diff changeset
24 ## @seealso{reallog, realsqrt}
7621
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
25 ## @end deftypefn
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
26
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
27 function z = realpow (x, y)
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
28 if (nargin != 2)
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
29 print_usage ();
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
30 else
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
31 z = x .^ y;
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
32 if (iscomplex (z))
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
33 error ("realpow: produced complex result");
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
34 endif
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
35 endif
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
36 endfunction
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
37
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
38 %!assert (power (1:10, 0.5:0.5:5), realpow (1:10, 0.5:0.5:5))
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
39 %!assert ([1:10] .^ [0.5:0.5:5], realpow (1:10, 0.5:0.5:5))
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
40 %!test
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
41 %! x = rand (10,10);
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
42 %! y = randn (10,10);
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
43 %! assert (x.^y,realpow(x,y))
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
44 %!assert (realpow(1i,2),-1)
4682dda22527 Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff changeset
45 %!error (realpow(-1, 1/2))