Mercurial > hg > octave-nkf
annotate scripts/specfun/pow2.m @ 14383:07c55bceca23 stable
Fix guarded_eval() subfunction in fminunc (bug #35534).
* fminunc.m: Fix guarded_eval() subfunction in fminunc (bug #35534).
author | Olaf Till <olaf.till@uni-jena.de> |
---|---|
date | Wed, 15 Feb 2012 14:44:37 +0100 |
parents | 72c96de7a403 |
children | f3d52523cde1 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1 ## Copyright (C) 1995-2012 Kurt Hornik |
3426 | 2 ## |
3922 | 3 ## This file is part of Octave. |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
3426 | 9 ## |
3922 | 10 ## Octave is distributed in the hope that it will be useful, but |
2537 | 11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
3426 | 13 ## General Public License for more details. |
14 ## | |
2537 | 15 ## You should have received a copy of the GNU General Public License |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
2537 | 18 |
3321 | 19 ## -*- texinfo -*- |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
9167
diff
changeset
|
20 ## @deftypefn {Mapping Function} {} pow2 (@var{x}) |
3321 | 21 ## @deftypefnx {Mapping Function} {} pow2 (@var{f}, @var{e}) |
22 ## With one argument, computes | |
23 ## @tex | |
9167
1231b1762a9a
Simplify TeXinfo and eliminate use of @iftex in arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9141
diff
changeset
|
24 ## $2^x$ |
3321 | 25 ## @end tex |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7742
diff
changeset
|
26 ## @ifnottex |
9167
1231b1762a9a
Simplify TeXinfo and eliminate use of @iftex in arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9141
diff
changeset
|
27 ## 2 .^ x |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7742
diff
changeset
|
28 ## @end ifnottex |
9141
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
29 ## for each element of @var{x}. |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
30 ## |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
31 ## With two arguments, returns |
3321 | 32 ## @tex |
9167
1231b1762a9a
Simplify TeXinfo and eliminate use of @iftex in arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9141
diff
changeset
|
33 ## $f \cdot 2^e$. |
3321 | 34 ## @end tex |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7742
diff
changeset
|
35 ## @ifnottex |
9167
1231b1762a9a
Simplify TeXinfo and eliminate use of @iftex in arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9141
diff
changeset
|
36 ## f .* (2 .^ e). |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7742
diff
changeset
|
37 ## @end ifnottex |
9141
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
38 ## @seealso{log2, nextpow2} |
3321 | 39 ## @end deftypefn |
2537 | 40 |
41 ## Author: AW <Andreas.Weingessel@ci.tuwien.ac.at> | |
42 ## Created: 17 October 1994 | |
43 ## Adapted-By: jwe | |
44 | |
45 function y = pow2 (f, e) | |
3426 | 46 |
2537 | 47 if (nargin == 1) |
48 y = 2 .^ f; | |
49 elseif (nargin == 2) | |
50 y = f .* (2 .^ e); | |
51 else | |
6046 | 52 print_usage (); |
2537 | 53 endif |
54 | |
55 endfunction | |
7385 | 56 |
57 %!test | |
58 %! x = [3, 0, -3]; | |
59 %! v = [8, 1, .125]; | |
60 %! assert(all (abs (pow2 (x) - v) < sqrt (eps))); | |
61 | |
62 %!test | |
63 %! x = [3, 0, -3, 4, 0, -4, 5, 0, -5]; | |
64 %! y = [-2, -2, -2, 1, 1, 1, 3, 3, 3]; | |
65 %! z = x .* (2 .^ y); | |
7742 | 66 %! assert(all (abs (pow2 (x,y) - z) < sqrt (eps))); |
7385 | 67 |
68 %!error pow2(); | |
69 |