]> Creatis software - CreaPhase.git/blob - octave_packages/m/polynomial/ppint.m
update packages
[CreaPhase.git] / octave_packages / m / polynomial / ppint.m
1 ## Copyright (C) 2008-2012 VZLU Prague, a.s., Czech Republic
2 ##
3 ## This file is part of Octave.
4 ##
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.
9 ##
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.
14 ##
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/>.
18
19 ## -*- texinfo -*-
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}
25 ## @end deftypefn
26
27 function ppi = ppint (pp, c)
28   if (nargin < 1 || nargin > 2)
29     print_usage ();
30   endif
31   if (! (isstruct (pp) && strcmp (pp.form, "pp")))
32     error ("ppint: PP must be a structure");
33   endif
34
35   [x, p, n, k, d] = unmkpp (pp);
36   p = reshape (p, [], k);
37
38   ## Get piecewise antiderivatives
39   pi = p / diag (k:-1:1);
40   k += 1;
41   if (nargin == 1)
42     pi(:, k) = 0;
43   else
44     pi(:, k) = repmat (c(:), n, 1);
45   endif
46
47   ppi = mkpp (x, pi, d);
48
49   tmp = -cumsum (ppjumps (ppi), length (d) + 1);
50   ppi.coefs(prod(d)+1:end, k) = tmp(:);
51
52 endfunction
53
54 %!shared x,y,pp,ppi
55 %! x=0:8;y=[ones(size(x));x+1];pp=spline(x,y);
56 %! ppi=ppint(pp);
57 %!assert(ppval(ppi,x),[x;0.5*x.^2+x],1e-14)
58 %!assert(ppi.order,5)