Mercurial > hg > octave-nkf
annotate scripts/polynomial/ppint.m @ 20279:db30302bedc3
Added tag rc-4-0-0-3 for changeset 065f933ef083
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 10 Apr 2015 14:41:21 -0400 |
parents | 4197fc428c7d |
children | f1d0f506ee78 |
rev | line source |
---|---|
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17795
diff
changeset
|
1 ## Copyright (C) 2008-2015 VZLU Prague, a.s., Czech Republic |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
2 ## |
9976
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
3 ## This file is part of Octave. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
4 ## |
9976
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
5 ## Octave is free software; you can redistribute it and/or modify |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
6 ## it under the terms of the GNU General Public License as published by |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
7 ## the Free Software Foundation; either version 3 of the License, or |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
8 ## (at your option) any later version. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
9 ## |
17795
0a8c35ae5ce1
maint: Fix various problems with GPL copyright statements.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
10 ## Octave is distributed in the hope that it will be useful, |
9976
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
13 ## GNU General Public License for more details. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
14 ## |
9976
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
15 ## You should have received a copy of the GNU General Public License |
17795
0a8c35ae5ce1
maint: Fix various problems with GPL copyright statements.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
16 ## along with Octave; see the file COPYING. If not, see |
9976
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
17 ## <http://www.gnu.org/licenses/>. |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
18 |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
19 ## -*- texinfo -*- |
11536
702dbd0c53f5
Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
20 ## @deftypefn {Function File} {@var{ppi} =} ppint (@var{pp}) |
702dbd0c53f5
Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
21 ## @deftypefnx {Function File} {@var{ppi} =} ppint (@var{pp}, @var{c}) |
702dbd0c53f5
Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
22 ## Compute the integral of the piecewise polynomial struct @var{pp}. |
9976
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
23 ## @var{c}, if given, is the constant of integration. |
12575
d0b799dafede
Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
24 ## @seealso{mkpp, ppval, ppder} |
9976
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
25 ## @end deftypefn |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
26 |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
27 function ppi = ppint (pp, c) |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
28 if (nargin < 1 || nargin > 2) |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
29 print_usage (); |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
30 endif |
13258
be74491c20e8
Correct typo in input validation of polynomial functions (Bug #33252)
Rik <octave@nomad.inbox5.com>
parents:
13141
diff
changeset
|
31 if (! (isstruct (pp) && strcmp (pp.form, "pp"))) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
32 error ("ppint: PP must be a structure"); |
9976
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
33 endif |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
34 |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
35 [x, p, n, k, d] = unmkpp (pp); |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
36 p = reshape (p, [], k); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
37 |
9976
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
38 ## Get piecewise antiderivatives |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
39 pi = p / diag (k:-1:1); |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
40 k += 1; |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
41 if (nargin == 1) |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
42 pi(:, k) = 0; |
9976
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
43 else |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
44 pi(:, k) = repmat (c(:), n, 1); |
9976
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
45 endif |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
46 |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
47 ppi = mkpp (x, pi, d); |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
48 |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
49 tmp = -cumsum (ppjumps (ppi), length (d) + 1); |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
50 ppi.coefs(prod (d)+1 : end, k) = tmp(:); |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12608
diff
changeset
|
51 |
9976
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
52 endfunction |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
53 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
54 |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
55 %!shared x,y,pp,ppi |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
56 %! x = 0:8; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
57 %! y = [ ones(size(x)); x+1 ]; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
58 %! pp = spline (x, y); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
59 %! ppi = ppint (pp); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
60 %!assert (ppval (ppi, x), [x; 0.5*x.^2 + x], 1e-14) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
61 %!assert (ppi.order, 5) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
62 |