Mercurial > hg > octave-lyh
annotate scripts/specfun/reallog.m @ 7621:4682dda22527
Add the reallog, realsqrt and realpow functions
author | David Bateman <dbateman@free.fr> |
---|---|
date | Fri, 21 Mar 2008 16:09:01 +0100 |
parents | |
children | 3eb2094eefe5 |
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} {} realsqrt (@var{x}) |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
21 ## Return the real natural logarithm of @var{x}. If any element results in the |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
22 ## return value being complex @code{reallog} produces an error. |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
23 ## @seealso{log, realsqrt, realpow} |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
24 ## @end deftypefn |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
25 |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
26 function y = reallog (x) |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
27 if (nargin != 1) |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
28 print_usage (); |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
29 elseif (iscomplex (x) || any (x(:) < 0)) |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
30 error ("reallog: produced complex result"); |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
31 else |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
32 y = log (x); |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
33 endif |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
34 endfunction |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
35 |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
36 %!assert (log(1:5),reallog(1:5)) |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
37 %!test |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
38 %! x = rand (10,10); |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
39 %! assert (log(x),reallog(x)) |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
40 %!error (reallog(-1)) |