Mercurial > hg > octave-lyh
annotate scripts/statistics/base/std.m @ 9211:f0c3d3fc4903
Simplify Texinfo documentation in .m scripts by removing redundant @iftex calls
author | Rik <rdrider0-list@yahoo.com> |
---|---|
date | Sun, 17 May 2009 14:39:39 -0700 |
parents | 1bf0ce0930be |
children | bb37822e9b82 |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 1996, 1997, 1998, 1999, 2000, 2004, 2005, 2006, 2007, 2008, |
2 ## 2009 John W. Eaton | |
3200 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
3200 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
3200 | 19 |
3367 | 20 ## -*- texinfo -*- |
21 ## @deftypefn {Function File} {} std (@var{x}) | |
4844 | 22 ## @deftypefnx {Function File} {} std (@var{x}, @var{opt}) |
23 ## @deftypefnx {Function File} {} std (@var{x}, @var{opt}, @var{dim}) | |
3367 | 24 ## If @var{x} is a vector, compute the standard deviation of the elements |
25 ## of @var{x}. | |
26 ## @tex | |
27 ## $$ | |
6754 | 28 ## {\rm std} (x) = \sigma (x) = \sqrt{{\sum_{i=1}^N (x_i - \bar{x})^2 \over N - 1}} |
3367 | 29 ## $$ |
6754 | 30 ## where $\bar{x}$ is the mean value of $x$. |
3367 | 31 ## @end tex |
6754 | 32 ## @ifnottex |
3426 | 33 ## |
3367 | 34 ## @example |
35 ## @group | |
36 ## std (x) = sqrt (sumsq (x - mean (x)) / (n - 1)) | |
37 ## @end group | |
38 ## @end example | |
6754 | 39 ## @end ifnottex |
3367 | 40 ## If @var{x} is a matrix, compute the standard deviation for |
41 ## each column and return them in a row vector. | |
4844 | 42 ## |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8977
diff
changeset
|
43 ## The argument @var{opt} determines the type of normalization to use. Valid values |
4844 | 44 ## are |
45 ## | |
46 ## @table @asis | |
47 ## @item 0: | |
6754 | 48 ## normalizes with @math{N-1}, provides the square root of best unbiased estimator of |
4844 | 49 ## the variance [default] |
50 ## @item 1: | |
6754 | 51 ## normalizes with @math{N}, this provides the square root of the second moment around |
4844 | 52 ## the mean |
53 ## @end table | |
54 ## | |
55 ## The third argument @var{dim} determines the dimension along which the standard | |
56 ## deviation is calculated. | |
5642 | 57 ## @seealso{mean, median} |
3367 | 58 ## @end deftypefn |
3200 | 59 |
60 ## Author: jwe | |
61 | |
4844 | 62 function retval = std (a, opt, dim) |
3200 | 63 |
4844 | 64 if (nargin < 1 || nargin > 3) |
6046 | 65 print_usage (); |
4844 | 66 endif |
67 if nargin < 3 | |
6024 | 68 dim = find (size (a) > 1, 1); |
8507 | 69 if (isempty (dim)) |
70 dim = 1; | |
71 endif | |
4844 | 72 endif |
8507 | 73 if (nargin < 2 || isempty (opt)) |
4844 | 74 opt = 0; |
3200 | 75 endif |
76 | |
8977
f464119ec165
further simplify some stats funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
77 n = size (a, dim); |
f464119ec165
further simplify some stats funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
78 if (n == 1) |
f464119ec165
further simplify some stats funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
79 retval = zeros (sz); |
4844 | 80 elseif (numel (a) > 0) |
8977
f464119ec165
further simplify some stats funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
81 retval = sqrt (sumsq (center (a, dim), dim) / (n + opt - 1)); |
3200 | 82 else |
8977
f464119ec165
further simplify some stats funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
83 error ("std: x must not be empty"); |
3200 | 84 endif |
85 | |
86 endfunction | |
7411 | 87 |
88 %!test | |
89 %! x = ones (10, 2); | |
90 %! y = [1, 3]; | |
91 %! assert(std (x) == [0, 0] && abs (std (y) - sqrt (2)) < sqrt (eps)); | |
92 | |
93 %!error std (); | |
94 | |
95 %!error std (1, 2, 3, 4); | |
96 |