annotate scripts/polynomial/ppjumps.m @ 20654:b65888ec820e draft default tip gccjit

dmalcom gcc jit import
author Stefan Mahr <dac922@gmx.de>
date Fri, 27 Feb 2015 16:59:36 +0100
parents f1d0f506ee78
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19731
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 -*-
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
20 ## @deftypefn {Function File} {@var{jumps} =} ppjumps (@var{pp})
11536
702dbd0c53f5 Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
21 ## Evaluate the boundary jumps of a piecewise polynomial.
20200
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19731
diff changeset
22 ##
11536
702dbd0c53f5 Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
23 ## If there are @math{n} intervals, and the dimensionality of @var{pp} is
702dbd0c53f5 Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
24 ## @math{d}, the resulting array has dimensions @code{[d, n-1]}.
702dbd0c53f5 Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
25 ## @seealso{mkpp}
9976
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
26 ## @end deftypefn
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
27
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
28 function jumps = ppjumps (pp)
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
29 if (nargin != 1)
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
30 print_usage ();
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
31 endif
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 13051
diff changeset
32
13258
be74491c20e8 Correct typo in input validation of polynomial functions (Bug #33252)
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
33 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
34 error ("ppjumps: PP must be a structure");
9976
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
35 endif
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
36
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
37 ## Extract info.
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
38 [x, P, n, k, d] = unmkpp (pp);
12608
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
39 nd = length (d) + 1;
9976
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
40
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
41 ## Offsets.
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
42 dx = diff (x(1:n));
12608
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
43 dx = repmat (dx, [prod(d), 1]);
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
44 dx = reshape (dx, [d, n-1]);
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
45 dx = shiftdim (dx, nd - 1);
9976
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
46
12608
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
47 ## Use Horner scheme.
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
48 if (k>1)
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
49 llim = shiftdim (reshape (P(1:(n-1) * prod (d), 1), [d, n-1]), nd - 1);
12608
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
50 endif
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
51
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
52 for i = 2 : k;
9976
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
53 llim .*= dx;
12608
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
54 llim += shiftdim (reshape (P(1:(n-1) * prod (d), i), [d, n-1]), nd - 1);
9976
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
55 endfor
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 13051
diff changeset
56
12608
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
57 rlim = shiftdim (ppval (pp, x(2:end-1)), nd - 1);
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
58 jumps = shiftdim (rlim - llim, 1);
9976
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
59 endfunction
13051
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
60
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
61
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
62 %!test
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
63 %! p = [1 6 11 6];
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
64 %! x = linspace (5, 6, 4);
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
65 %! y = polyval (p, x);
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
66 %! pp = spline (x, y);
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
67 %! jj = ppjumps (pp);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
68 %! assert (jj, [0 0], eps);
13051
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
69
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
70 %!test
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
71 %! breaks = [0 1 2];
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
72 %! pp1 = poly (-[1 2 3]);
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
73 %! pp2 = poly (-([1 2 3]+1));
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
74 %! pp = mkpp (breaks, [pp1;pp2]);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
75 %! assert (ppjumps (pp), 0, eps);
13051
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
76
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
77 %!test
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
78 %! breaks = [0 1 2];
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
79 %! pp1 = poly (-[1 2 3]);
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
80 %! pp2 = poly (([1 2 3]+1));
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
81 %! pp = mkpp (breaks, [pp1;pp2]);
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
82 %! j = - 2 * polyval (pp1, 1);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
83 %! assert (ppjumps (pp), j, eps);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
84