Mercurial > hg > octave-nkf
annotate scripts/signal/sinc.m @ 13818:a05e5db7b94e
have some fun with waitbar demo #2
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 04 Nov 2011 14:33:44 -0400 |
parents | cd59f5271941 |
children | 72c96de7a403 |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 1994-2011 John W. Eaton |
2313 | 2 ## |
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. | |
2313 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
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/>. | |
2303 | 18 |
3367 | 19 ## -*- texinfo -*- |
20 ## @deftypefn {Function File} {} sinc (@var{x}) | |
21 ## Return | |
22 ## @tex | |
23 ## $ \sin (\pi x)/(\pi x)$. | |
24 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7125
diff
changeset
|
25 ## @ifnottex |
3367 | 26 ## sin(pi*x)/(pi*x). |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7125
diff
changeset
|
27 ## @end ifnottex |
3367 | 28 ## @end deftypefn |
559 | 29 |
3367 | 30 ## Author: jwe ??? |
2314 | 31 |
2311 | 32 function result = sinc (x) |
559 | 33 |
7125 | 34 if (nargin != 1) |
35 print_usage (); | |
36 endif | |
37 | |
3486 | 38 result = ones (size (x)); |
559 | 39 |
3486 | 40 i = (x != 0); |
559 | 41 |
4807 | 42 if (any (i(:))) |
3486 | 43 t = pi * x(i); |
44 result(i) = sin (t) ./ t; | |
559 | 45 endif |
46 | |
47 endfunction | |
12816
cd59f5271941
codesprint: Wrote 4 tests for sinc.m
Giles Anderson <agander@gmail.com>
parents:
11523
diff
changeset
|
48 |
cd59f5271941
codesprint: Wrote 4 tests for sinc.m
Giles Anderson <agander@gmail.com>
parents:
11523
diff
changeset
|
49 |
cd59f5271941
codesprint: Wrote 4 tests for sinc.m
Giles Anderson <agander@gmail.com>
parents:
11523
diff
changeset
|
50 %!assert (sinc (0), 1); |
cd59f5271941
codesprint: Wrote 4 tests for sinc.m
Giles Anderson <agander@gmail.com>
parents:
11523
diff
changeset
|
51 %!assert (sinc (1), 0,1e-6); |
cd59f5271941
codesprint: Wrote 4 tests for sinc.m
Giles Anderson <agander@gmail.com>
parents:
11523
diff
changeset
|
52 %!assert (sinc (1/2), 2/pi, 1e-6) |
cd59f5271941
codesprint: Wrote 4 tests for sinc.m
Giles Anderson <agander@gmail.com>
parents:
11523
diff
changeset
|
53 |
cd59f5271941
codesprint: Wrote 4 tests for sinc.m
Giles Anderson <agander@gmail.com>
parents:
11523
diff
changeset
|
54 %!error sinc() |