annotate scripts/general/cumtrapz.m @ 26376:00f796120a6d stable

maint: Update copyright dates in all source files.
author John W. Eaton <jwe@octave.org>
date Wed, 02 Jan 2019 16:32:43 -0500
parents 7d7970c7b3e8
children b442ec6dda5c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26376
00f796120a6d maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 25577
diff changeset
1 ## Copyright (C) 2000-2019 Kai Habel
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
2 ##
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
4 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
5 ## Octave is free software: you can redistribute it and/or modify it
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
7 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
8 ## (at your option) any later version.
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
9 ##
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
13 ## GNU General Public License for more details.
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
14 ##
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
17 ## <https://www.gnu.org/licenses/>.
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
18
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20617
diff changeset
20 ## @deftypefn {} {@var{q} =} cumtrapz (@var{y})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20617
diff changeset
21 ## @deftypefnx {} {@var{q} =} cumtrapz (@var{x}, @var{y})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20617
diff changeset
22 ## @deftypefnx {} {@var{q} =} cumtrapz (@dots{}, @var{dim})
12612
16cca721117b doc: Update all documentation for chapter on Numerical Integration
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
23 ## Cumulative numerical integration of points @var{y} using the trapezoidal
16cca721117b doc: Update all documentation for chapter on Numerical Integration
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
24 ## method.
20158
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
25 ##
12612
16cca721117b doc: Update all documentation for chapter on Numerical Integration
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
26 ## @w{@code{cumtrapz (@var{y})}} computes the cumulative integral of @var{y}
20158
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
27 ## along the first non-singleton dimension. Where @code{trapz} reports only
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
28 ## the overall integral sum, @code{cumtrapz} reports the current partial sum
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
29 ## value at each point of @var{y}.
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
30 ##
20158
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
31 ## When the argument @var{x} is omitted an equally spaced @var{x} vector with
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
32 ## unit spacing (1) is assumed. @code{cumtrapz (@var{x}, @var{y})} evaluates
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
33 ## the integral with respect to the spacing in @var{x} and the values in
21546
f7f97d7e9294 doc: Wrap m-file docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents: 20852
diff changeset
34 ## @var{y}. This is useful if the points in @var{y} have been sampled
f7f97d7e9294 doc: Wrap m-file docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents: 20852
diff changeset
35 ## unevenly.
20158
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
36 ##
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
37 ## If the optional @var{dim} argument is given, operate along this dimension.
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
38 ##
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
39 ## Application Note: If @var{x} is not specified then unit spacing will be
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
40 ## used. To scale the integral to the correct value you must multiply by the
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
41 ## actual spacing value (deltaX).
12575
d0b799dafede Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
42 ## @seealso{trapz, cumsum}
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
43 ## @end deftypefn
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
44
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
45 ## Author: Kai Habel <kai.habel@gmx.de>
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
46 ##
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
47 ## also: June 2000 Paul Kienzle (fixes,suggestions)
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
48 ## 2006-05-12 David Bateman - Modified for NDArrays
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
49
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
50 function z = cumtrapz (x, y, dim)
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
51
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
52 if (nargin < 1) || (nargin > 3)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5820
diff changeset
53 print_usage ();
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
54 endif
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
55
12667
d8aff843a9e9 Accept input x vector with y matrix for trapz,cumtrapz (bug #33292).
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
56 have_xy = have_dim = false;
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
57
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
58 if (nargin == 3)
12667
d8aff843a9e9 Accept input x vector with y matrix for trapz,cumtrapz (bug #33292).
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
59 have_xy = true;
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
60 have_dim = true;
10690
35adf2a71f3f Use common code block to find first non-singleton dimension.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
61 elseif (nargin == 2)
25577
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
62 if (isscalar (y) && ! isscalar (x))
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
63 have_dim = true;
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
64 dim = y;
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
65 else
12667
d8aff843a9e9 Accept input x vector with y matrix for trapz,cumtrapz (bug #33292).
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
66 have_xy = true;
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
67 endif
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
68 endif
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
69
12667
d8aff843a9e9 Accept input x vector with y matrix for trapz,cumtrapz (bug #33292).
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
70 if (have_xy)
d8aff843a9e9 Accept input x vector with y matrix for trapz,cumtrapz (bug #33292).
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
71 nd = ndims (y);
d8aff843a9e9 Accept input x vector with y matrix for trapz,cumtrapz (bug #33292).
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
72 sz = size (y);
d8aff843a9e9 Accept input x vector with y matrix for trapz,cumtrapz (bug #33292).
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
73 else
d8aff843a9e9 Accept input x vector with y matrix for trapz,cumtrapz (bug #33292).
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
74 nd = ndims (x);
d8aff843a9e9 Accept input x vector with y matrix for trapz,cumtrapz (bug #33292).
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
75 sz = size (x);
d8aff843a9e9 Accept input x vector with y matrix for trapz,cumtrapz (bug #33292).
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
76 endif
d8aff843a9e9 Accept input x vector with y matrix for trapz,cumtrapz (bug #33292).
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
77
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
78 if (! have_dim)
10690
35adf2a71f3f Use common code block to find first non-singleton dimension.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
79 ## Find the first non-singleton dimension.
12667
d8aff843a9e9 Accept input x vector with y matrix for trapz,cumtrapz (bug #33292).
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
80 (dim = find (sz > 1, 1)) || (dim = 1);
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
81 else
12667
d8aff843a9e9 Accept input x vector with y matrix for trapz,cumtrapz (bug #33292).
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
82 if (!(isscalar (dim) && dim == fix (dim))
d8aff843a9e9 Accept input x vector with y matrix for trapz,cumtrapz (bug #33292).
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
83 || !(1 <= dim && dim <= nd))
d8aff843a9e9 Accept input x vector with y matrix for trapz,cumtrapz (bug #33292).
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
84 error ("trapz: DIM must be an integer and a valid dimension");
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
85 endif
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
86 endif
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
87
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
88 n = sz(dim);
25577
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
89 idx1 = idx2 = {':'}(ones (nd, 1)); # repmat ({':'}, [nd, 1]), but faster
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
90 idx1{dim} = 2 : n;
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
91 idx2{dim} = 1 : (n - 1);
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
92
12667
d8aff843a9e9 Accept input x vector with y matrix for trapz,cumtrapz (bug #33292).
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
93 if (! have_xy)
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
94 z = 0.5 * cumsum (x(idx1{:}) + x(idx2{:}), dim);
25577
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
95 elseif (isscalar (x))
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
96 z = x * 0.5 * cumsum (y(idx1{:}) + y(idx2{:}), dim);
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
97 elseif (isvector (x))
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
98 if (length (x) != n)
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
99 error ("cumtrapz: length of X and length of Y along DIM must match");
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
100 endif
12667
d8aff843a9e9 Accept input x vector with y matrix for trapz,cumtrapz (bug #33292).
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
101 ## Reshape vector to point along dimension DIM
d8aff843a9e9 Accept input x vector with y matrix for trapz,cumtrapz (bug #33292).
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
102 shape = ones (nd, 1);
25577
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
103 shape(dim) = n;
12667
d8aff843a9e9 Accept input x vector with y matrix for trapz,cumtrapz (bug #33292).
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
104 x = reshape (x, shape);
20617
a3b9ee5c040a Replace bsxfun with broadcasting for performance with complex inputs (bug #38628).
Rik <rik@octave.org>
parents: 20158
diff changeset
105 z = 0.5 * cumsum (diff (x) .* (y(idx1{:}) + y(idx2{:})), dim);
25577
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
106 else
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
107 if (! size_equal (x, y))
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
108 error ("cumtrapz: X and Y must have same shape");
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
109 endif
25577
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
110 z = 0.5 * cumsum (diff (x, 1, dim) .* (y(idx1{:}) + y(idx2{:})), dim);
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
111 endif
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
112
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
113 sz(dim) = 1;
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
114 z = cat (dim, zeros (sz), z);
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
115
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
116 endfunction
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
117
12667
d8aff843a9e9 Accept input x vector with y matrix for trapz,cumtrapz (bug #33292).
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
118
25577
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
119 %!shared x1, x2, y
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
120 %! x1 = [1:5];
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
121 %! x2 = [2:2:10];
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
122 %! y = [1:5];
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
123 %!
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
124 %!assert (cumtrapz (y), [0, 1.5, 4, 7.5, 12])
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
125 %!assert (cumtrapz (y'), [0, 1.5, 4, 7.5, 12]')
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
126 %!assert (cumtrapz (1, y), [0, 1.5, 4, 7.5, 12])
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
127 %!assert (cumtrapz (2, y), [0, 3, 8, 15, 24])
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
128 %!assert (cumtrapz (x1, y),[0, 1.5, 4, 7.5, 12])
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
129 %!assert (cumtrapz (x2, y),[0, 3, 8, 15, 24])
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
130 %!assert (cumtrapz (2, y, 2), [0, 3, 8, 15, 24])
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
131 %!assert (cumtrapz (x2, y, 2), [0, 3, 8, 15, 24])
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
132 %!assert (cumtrapz (y, 1), [0, 0, 0, 0, 0])
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
133 %!assert (cumtrapz (2, y, 1), [0, 0, 0, 0, 0])
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
134 %!assert (cumtrapz (y', 2), [0, 0, 0, 0, 0]')
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
135
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
136 %!shared x1, x2, y
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
137 %! x1 = [0,0,0;2,2,2];
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
138 %! x2 = [0,2,4;0,2,4];
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
139 %! y = [1,2,3;4,5,6];
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
140 %!
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
141 %!assert (cumtrapz (y), [0,0,0;2.5,3.5,4.5])
25577
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
142 %!assert (cumtrapz (x1, y), [0,0,0;5,7,9])
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
143 %!assert (cumtrapz (y, 1), [0,0,0;2.5,3.5,4.5])
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
144 %!assert (cumtrapz (x1, y, 1), [0,0,0;5,7,9])
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
145 %!assert (cumtrapz (y, 2), [0,1.5,4;0,4.5,10])
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
146 %!assert (cumtrapz (x2, y, 2), [0,3,8;0,9,20])
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
147
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
148 ## Test ND-array implementation
12667
d8aff843a9e9 Accept input x vector with y matrix for trapz,cumtrapz (bug #33292).
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
149 %!shared x1,x2,y
d8aff843a9e9 Accept input x vector with y matrix for trapz,cumtrapz (bug #33292).
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
150 %! x1 = 1:3;
d8aff843a9e9 Accept input x vector with y matrix for trapz,cumtrapz (bug #33292).
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
151 %! x2 = reshape ([0,2,4;0,2,4], [1 2 3]);
d8aff843a9e9 Accept input x vector with y matrix for trapz,cumtrapz (bug #33292).
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
152 %! y = reshape ([1,2,3;4,5,6], [1 2 3]);
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
153 %!
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
154 %!assert (cumtrapz (y,3), reshape ([0,1.5,4;0,4.5,10],[1 2 3]))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
155 %!assert (cumtrapz (x1,y,3), reshape ([0,1.5,4;0,4.5,10],[1 2 3]))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
156 %!assert (cumtrapz (x2,y,3), reshape ([0,3,8;0,9,20],[1 2 3]))
25577
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
157
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
158 ## Test input validation
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
159 %!error cumtrapz ()
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
160 %!error cumtrapz (1,2,3,4)
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
161 %!error <DIM must be an integer> cumtrapz (1, 2, [1 2])
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
162 %!error <DIM must be an integer> cumtrapz (1, 2, 1.5)
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
163 %!error <DIM must be .* a valid dimension> cumtrapz (1, 2, 0)
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
164 %!error <length of X and length of Y.*must match> cumtrapz ([1 2], [1 2 3])
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
165 %!error <X and Y must have same shape> cumtrapz (ones (2,3), ones (2,4))
7d7970c7b3e8 cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents: 25054
diff changeset
166