1 ## Copyright (C) 2008-2012 VZLU Prague, a.s., Czech Republic
3 ## This file is part of Octave.
5 ## Octave is free software; you can redistribute it and/or modify
6 ## it under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or
8 ## (at your option) any later version.
10 ## This program is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ## GNU General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with this software; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {@var{jumps} =} ppjumps (@var{pp})
21 ## Evaluate the boundary jumps of a piecewise polynomial.
22 ## If there are @math{n} intervals, and the dimensionality of @var{pp} is
23 ## @math{d}, the resulting array has dimensions @code{[d, n-1]}.
27 function jumps = ppjumps (pp)
32 if (! (isstruct (pp) && strcmp (pp.form, "pp")))
33 error ("ppjumps: PP must be a structure");
37 [x, P, n, k, d] = unmkpp(pp);
42 dx = repmat (dx, [prod(d), 1]);
43 dx = reshape (dx, [d, n-1]);
44 dx = shiftdim (dx, nd - 1);
48 llim = shiftdim (reshape (P(1:(n-1) * prod(d), 1), [d, n-1]), nd - 1);
53 llim += shiftdim (reshape (P(1:(n-1) * prod (d), i), [d, n-1]), nd - 1);
56 rlim = shiftdim (ppval (pp, x(2:end-1)), nd - 1);
57 jumps = shiftdim (rlim - llim, 1);
63 %! x = linspace (5, 6, 4);
64 %! y = polyval (p, x);
65 %! pp = spline (x, y);
67 %! assert (jj, [0 0], eps)
72 %! pp1 = poly (-[1 2 3]);
73 %! pp2 = poly (-([1 2 3]+1));
74 %! pp = mkpp (breaks, [pp1;pp2]);
75 %! assert (ppjumps (pp), 0, eps)
80 %! pp1 = poly (-[1 2 3]);
81 %! pp2 = poly (([1 2 3]+1));
82 %! pp = mkpp (breaks, [pp1;pp2]);
83 %! j = - 2 * polyval (pp1, 1);
84 %! assert (ppjumps (pp), j, eps)