Mercurial > octave-nkf
annotate scripts/statistics/base/moment.m @ 14138:72c96de7a403 stable
maint: update copyright notices for 2012
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 02 Jan 2012 14:25:41 -0500 |
parents | 6b2f14af2360 |
children | 4d917a6a858b |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
12656
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 |
3200 | 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 ## | |
3200 | 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/>. | |
3200 | 18 |
3453 | 19 ## -*- texinfo -*- |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
20 ## @deftypefn {Function File} {} moment (@var{x}, @var{p}) |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
21 ## @deftypefnx {Function File} {} moment (@var{x}, @var{p}, @var{type}) |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
22 ## @deftypefnx {Function File} {} moment (@var{x}, @var{p}, @var{dim}) |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
23 ## @deftypefnx {Function File} {} moment (@var{x}, @var{p}, @var{type}, @var{dim}) |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
24 ## @deftypefnx {Function File} {} moment (@var{x}, @var{p}, @var{dim}, @var{type}) |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
25 ## Compute the @var{p}-th moment of the vector @var{x} about zero. |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
26 ## @tex |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
27 ## $$ |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
28 ## {\rm moment} (x) = { \sum_{i=1}^N {x_i}^p \over N } |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
29 ## $$ |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
30 ## @end tex |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
31 ## @ifnottex |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
32 ## |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
33 ## @example |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
34 ## @group |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
35 ## moment (x) = 1/N SUM_i x(i)^p |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
36 ## @end group |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
37 ## @end example |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
38 ## |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
39 ## @end ifnottex |
3200 | 40 ## |
3453 | 41 ## If @var{x} is a matrix, return the row vector containing the |
42 ## @var{p}-th moment of each column. | |
3200 | 43 ## |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
44 ## The optional string @var{type} specifies the type of moment to be computed. |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
45 ## Valid options are: |
11595
5ec6aa05638d
Prevent doubled quotes around @table items in Info.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
46 ## @table @asis |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
47 ## @item "c" |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
48 ## Central Moment. The moment about the mean defined as |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
49 ## @tex |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
50 ## $$ |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
51 ## {\sum_{i=1}^N (x_i - \bar{x})^p \over N} |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
52 ## $$ |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
53 ## @end tex |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
54 ## @ifnottex |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
55 ## |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
56 ## @example |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
57 ## @group |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
58 ## 1/N SUM_i (x(i) - mean(x))^p |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
59 ## @end group |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
60 ## @end example |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
61 ## |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
62 ## @end ifnottex |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
63 ## |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
64 ## @item "a" |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
65 ## Absolute Moment. The moment about zero ignoring sign defined as |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
66 ## @tex |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
67 ## $$ |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
68 ## {\sum_{i=1}^N {\left| x_i \right|}^p \over N} |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
69 ## $$ |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
70 ## @end tex |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
71 ## @ifnottex |
3453 | 72 ## |
73 ## @example | |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
74 ## @group |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
75 ## 1/N SUM_i ( abs(x(i)) )^p |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
76 ## @end group |
3453 | 77 ## @end example |
78 ## | |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
79 ## @end ifnottex |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
80 ## |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
81 ## @item "ac" |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
82 ## Absolute Central Moment. Defined as |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
83 ## @tex |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
84 ## $$ |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
85 ## {\sum_{i=1}^N {\left| x_i - \bar{x} \right|}^p \over N} |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
86 ## $$ |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
87 ## @end tex |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
88 ## @ifnottex |
4844 | 89 ## |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
90 ## @example |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
91 ## @group |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
92 ## 1/N SUM_i ( abs(x(i) - mean(x)) )^p |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
93 ## @end group |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
94 ## @end example |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
95 ## |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
96 ## @end ifnottex |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
97 ## @end table |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
98 ## |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
99 ## If the optional argument @var{dim} is given, operate along this dimension. |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
100 ## |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
101 ## If both @var{type} and @var{dim} are given they may appear in any order. |
12575
d0b799dafede
Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents:
11595
diff
changeset
|
102 ## @seealso{var, skewness, kurtosis} |
3453 | 103 ## @end deftypefn |
3200 | 104 |
105 ## Can easily be made to work for continuous distributions (using quad) | |
106 ## as well, but how does the general case work? | |
3426 | 107 |
5428 | 108 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
3456 | 109 ## Description: Compute moments |
3426 | 110 |
4844 | 111 function m = moment (x, p, opt1, opt2) |
3426 | 112 |
12656
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
113 if (nargin < 2 || nargin > 4) |
6046 | 114 print_usage (); |
3200 | 115 endif |
3426 | 116 |
12656
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
117 if (!(isnumeric (x) || islogical (x)) || isempty (x)) |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
118 error ("moment: X must be a non-empty numeric matrix or vector"); |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
119 endif |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
120 |
12656
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
121 if (! (isnumeric (p) && isscalar (p))) |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
122 error ("moment: P must be a numeric scalar"); |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
123 endif |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
124 |
12656
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
125 need_dim = false; |
4844 | 126 |
5090 | 127 if (nargin == 2) |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
128 type = ""; |
12656
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
129 need_dim = true; |
5090 | 130 elseif (nargin == 3) |
5443 | 131 if (ischar (opt1)) |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
132 type = opt1; |
12656
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
133 need_dim = true; |
4844 | 134 else |
135 dim = opt1; | |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
136 type = ""; |
4844 | 137 endif |
5090 | 138 elseif (nargin == 4) |
5443 | 139 if (ischar (opt1)) |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
140 type = opt1; |
4844 | 141 dim = opt2; |
5443 | 142 elseif (ischar (opt2)) |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
143 type = opt2; |
4844 | 144 dim = opt1; |
145 else | |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
146 error ("moment: expecting TYPE to be a string"); |
4844 | 147 endif |
148 endif | |
149 | |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
150 nd = ndims (x); |
4844 | 151 sz = size (x); |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
152 if (need_dim) |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
153 ## Find the first non-singleton dimension. |
12656
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
154 (dim = find (sz > 1, 1)) || (dim = 1); |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
155 else |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
156 if (!(isscalar (dim) && dim == fix (dim)) || |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
157 !(1 <= dim && dim <= nd)) |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
158 error ("moment: DIM must be an integer and a valid dimension"); |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
159 endif |
3200 | 160 endif |
3426 | 161 |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
162 n = sz(dim); |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
163 |
12656
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
164 if (any (type == "c")) |
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
165 x = center (x, dim); |
5568 | 166 endif |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
167 if any (type == "a") |
5568 | 168 x = abs (x); |
169 endif | |
4844 | 170 |
5568 | 171 m = sum (x .^ p, dim) / n; |
3426 | 172 |
3200 | 173 endfunction |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
174 |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
175 |
12656
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
176 %!test |
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
177 %! x = rand (10); |
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
178 %! assert (moment (x,1), mean (x), 1e1*eps); |
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
179 %! assert (moment (x,2), meansq (x), 1e1*eps); |
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
180 %! assert (moment (x,1,2), mean (x,2), 1e1*eps); |
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
181 %! assert (moment (x,1,'c'), mean (center (x)), 1e1*eps); |
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
182 %! assert (moment (x,1,'a'), mean (abs (x)), 1e1*eps); |
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
183 |
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
184 %!assert (moment (single([1 2 3]),1), single(2)); |
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
185 |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
186 %% Test input validation |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
187 %!error moment () |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
188 %!error moment (1) |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
189 %!error moment (1, 2, 3, 4, 5) |
12656
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
190 %!error moment (['A'; 'B'], 2) |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
191 %!error moment (ones(2,0,3), 2) |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
192 %!error moment (1, true) |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
193 %!error moment (1, ones(2,2)) |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
194 %!error moment (1, 2, 3, 4) |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
195 %!error moment (1, 2, ones(2,2)) |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
196 %!error moment (1, 2, 1.5) |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
197 %!error moment (1, 2, 4) |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
198 |