Mercurial > octave
annotate scripts/general/cumtrapz.m @ 33617:ec2635a02328 bytecode-interpreter tip
maint: Merge default to bytecode-interpreter.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Tue, 21 May 2024 18:29:03 +0200 |
parents | 2e484f9f1f18 |
children |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
32632
2e484f9f1f18
maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
32426
diff
changeset
|
3 ## Copyright (C) 2000-2024 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
5820 | 7 ## |
8 ## This file is part of Octave. | |
9 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
5820 | 11 ## 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
|
12 ## 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
|
13 ## (at your option) any later version. |
5820 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
18 ## GNU General Public License for more details. |
5820 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
7016 | 21 ## 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
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
5820 | 25 |
26 ## -*- texinfo -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20617
diff
changeset
|
27 ## @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
|
28 ## @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
|
29 ## @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
|
30 ## 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
|
31 ## method. |
20158
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
32 ## |
12612
16cca721117b
doc: Update all documentation for chapter on Numerical Integration
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
33 ## @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
|
34 ## 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
|
35 ## 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
|
36 ## 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
|
37 ## |
20158
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
38 ## 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
|
39 ## 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
|
40 ## 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
|
41 ## @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
|
42 ## unevenly. |
20158
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
43 ## |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
44 ## 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
|
45 ## |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
46 ## 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
|
47 ## 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
|
48 ## actual spacing value (deltaX). |
12575
d0b799dafede
Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
49 ## @seealso{trapz, cumsum} |
5820 | 50 ## @end deftypefn |
51 | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
52 function z = cumtrapz (x, y, dim) |
5820 | 53 |
28789
28de41192f3c
Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents:
27984
diff
changeset
|
54 if (nargin < 1) |
6046 | 55 print_usage (); |
5820 | 56 endif |
57 | |
12667
d8aff843a9e9
Accept input x vector with y matrix for trapz,cumtrapz (bug #33292).
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
58 have_xy = have_dim = false; |
5820 | 59 |
60 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
|
61 have_xy = true; |
5820 | 62 have_dim = true; |
10690
35adf2a71f3f
Use common code block to find first non-singleton dimension.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
63 elseif (nargin == 2) |
25577
7d7970c7b3e8
cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
64 if (isscalar (y) && ! isscalar (x)) |
7d7970c7b3e8
cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
65 have_dim = true; |
5820 | 66 dim = y; |
67 else | |
12667
d8aff843a9e9
Accept input x vector with y matrix for trapz,cumtrapz (bug #33292).
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
68 have_xy = true; |
5820 | 69 endif |
70 endif | |
71 | |
12667
d8aff843a9e9
Accept input x vector with y matrix for trapz,cumtrapz (bug #33292).
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
72 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
|
73 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
|
74 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
|
75 else |
d8aff843a9e9
Accept input x vector with y matrix for trapz,cumtrapz (bug #33292).
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
76 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
|
77 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
|
78 endif |
d8aff843a9e9
Accept input x vector with y matrix for trapz,cumtrapz (bug #33292).
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
79 |
5820 | 80 if (! have_dim) |
10690
35adf2a71f3f
Use common code block to find first non-singleton dimension.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
81 ## 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
|
82 (dim = find (sz > 1, 1)) || (dim = 1); |
5820 | 83 else |
12667
d8aff843a9e9
Accept input x vector with y matrix for trapz,cumtrapz (bug #33292).
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
84 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
|
85 || !(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
|
86 error ("trapz: DIM must be an integer and a valid dimension"); |
5820 | 87 endif |
88 endif | |
89 | |
90 n = sz(dim); | |
25577
7d7970c7b3e8
cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
91 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
|
92 idx1{dim} = 2 : n; |
5820 | 93 idx2{dim} = 1 : (n - 1); |
94 | |
12667
d8aff843a9e9
Accept input x vector with y matrix for trapz,cumtrapz (bug #33292).
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
95 if (! have_xy) |
5820 | 96 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
|
97 elseif (isscalar (x)) |
7d7970c7b3e8
cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
98 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
|
99 elseif (isvector (x)) |
7d7970c7b3e8
cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
100 if (length (x) != n) |
7d7970c7b3e8
cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
101 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
|
102 endif |
12667
d8aff843a9e9
Accept input x vector with y matrix for trapz,cumtrapz (bug #33292).
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
103 ## 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
|
104 shape = ones (nd, 1); |
25577
7d7970c7b3e8
cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
105 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
|
106 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
|
107 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
|
108 else |
7d7970c7b3e8
cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
109 if (! size_equal (x, y)) |
7d7970c7b3e8
cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
110 error ("cumtrapz: X and Y must have same shape"); |
5820 | 111 endif |
25577
7d7970c7b3e8
cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
112 z = 0.5 * cumsum (diff (x, 1, dim) .* (y(idx1{:}) + y(idx2{:})), dim); |
5820 | 113 endif |
114 | |
115 sz(dim) = 1; | |
116 z = cat (dim, zeros (sz), z); | |
117 | |
118 endfunction | |
119 | |
12667
d8aff843a9e9
Accept input x vector with y matrix for trapz,cumtrapz (bug #33292).
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
120 |
25577
7d7970c7b3e8
cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
121 %!shared x1, x2, y |
7d7970c7b3e8
cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
122 %! x1 = [1:5]; |
7d7970c7b3e8
cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
123 %! x2 = [2:2:10]; |
7d7970c7b3e8
cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
124 %! y = [1:5]; |
7d7970c7b3e8
cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
125 %! |
7d7970c7b3e8
cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
126 %!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
|
127 %!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
|
128 %!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
|
129 %!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
|
130 %!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
|
131 %!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
|
132 %!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
|
133 %!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
|
134 %!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
|
135 %!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
|
136 %!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
|
137 |
7d7970c7b3e8
cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
138 %!shared x1, x2, y |
5820 | 139 %! x1 = [0,0,0;2,2,2]; |
140 %! x2 = [0,2,4;0,2,4]; | |
141 %! 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
|
142 %! |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
143 %!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
|
144 %!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
|
145 %!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
|
146 %!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
|
147 %!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
|
148 %!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
|
149 |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
150 ## 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
|
151 %!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
|
152 %! 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
|
153 %! 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
|
154 %! 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
|
155 %! |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
156 %!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
|
157 %!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
|
158 %!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
|
159 |
7d7970c7b3e8
cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
160 ## Test input validation |
28886
d8318c12d903
test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents:
28789
diff
changeset
|
161 %!error <Invalid call> cumtrapz () |
25577
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 2]) |
7d7970c7b3e8
cumtrapz.m: Overhaul function to match trapz.m
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
163 %!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
|
164 %!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
|
165 %!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
|
166 %!error <X and Y must have same shape> cumtrapz (ones (2,3), ones (2,4)) |