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{ppi} =} ppint (@var{pp})
21 ## @deftypefnx {Function File} {@var{ppi} =} ppint (@var{pp}, @var{c})
22 ## Compute the integral of the piecewise polynomial struct @var{pp}.
23 ## @var{c}, if given, is the constant of integration.
24 ## @seealso{mkpp, ppval, ppder}
27 function ppi = ppint (pp, c)
28 if (nargin < 1 || nargin > 2)
31 if (! (isstruct (pp) && strcmp (pp.form, "pp")))
32 error ("ppint: PP must be a structure");
35 [x, p, n, k, d] = unmkpp (pp);
36 p = reshape (p, [], k);
38 ## Get piecewise antiderivatives
39 pi = p / diag (k:-1:1);
44 pi(:, k) = repmat (c(:), n, 1);
47 ppi = mkpp (x, pi, d);
49 tmp = -cumsum (ppjumps (ppi), length (d) + 1);
50 ppi.coefs(prod(d)+1:end, k) = tmp(:);
55 %! x=0:8;y=[ones(size(x));x+1];pp=spline(x,y);
57 %!assert(ppval(ppi,x),[x;0.5*x.^2+x],1e-14)