annotate scripts/polynomial/ppjumps.m @ 17535:c12c688a35ed default tip lyh

Fix warnings
author LYH <lyh.kernel@gmail.com>
date Fri, 27 Sep 2013 17:43:27 +0800
parents 5d3a684236b0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 13258
diff changeset
1 ## Copyright (C) 2008-2012 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 ##
9976
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
10 ## This program is distributed in the hope that it will be useful,
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
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
16 ## along with this software; see the file COPYING. If not, see
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.
702dbd0c53f5 Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
22 ## 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
23 ## @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
24 ## @seealso{mkpp}
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 jumps = ppjumps (pp)
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
28 if (nargin != 1)
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
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 13051
diff changeset
31
13258
be74491c20e8 Correct typo in input validation of polynomial functions (Bug #33252)
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
32 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
33 error ("ppjumps: PP must be a structure");
9976
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
34 endif
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
35
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
36 ## Extract info.
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
37 [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
38 nd = length (d) + 1;
9976
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
39
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
40 ## Offsets.
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
41 dx = diff (x(1:n));
12608
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
42 dx = repmat (dx, [prod(d), 1]);
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
43 dx = reshape (dx, [d, n-1]);
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
44 dx = shiftdim (dx, nd - 1);
9976
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
45
12608
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
46 ## Use Horner scheme.
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
47 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
48 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
49 endif
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
50
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
51 for i = 2 : k;
9976
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
52 llim .*= dx;
12608
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
53 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
54 endfor
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 13051
diff changeset
55
12608
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
56 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
57 jumps = shiftdim (rlim - llim, 1);
9976
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
58 endfunction
13051
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
59
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 %!test
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
62 %! p = [1 6 11 6];
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
63 %! x = linspace (5, 6, 4);
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
64 %! y = polyval (p, x);
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
65 %! pp = spline (x, y);
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
66 %! jj = ppjumps (pp);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
67 %! assert (jj, [0 0], eps);
13051
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
68
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
69 %!test
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
70 %! breaks = [0 1 2];
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
71 %! pp1 = poly (-[1 2 3]);
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
72 %! pp2 = poly (-([1 2 3]+1));
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
73 %! 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
74 %! assert (ppjumps (pp), 0, eps);
13051
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
75
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
76 %!test
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
77 %! breaks = [0 1 2];
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
78 %! pp1 = poly (-[1 2 3]);
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
79 %! pp2 = poly (([1 2 3]+1));
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
80 %! pp = mkpp (breaks, [pp1;pp2]);
42e12f94fe1e Add 3 tests to ppjumps
Carlo de Falco <kingcrimson@tiscali.it>
parents: 12608
diff changeset
81 %! 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
82 %! 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
83