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} {ppd =} ppder (pp)
21 ## @deftypefnx {Function File} {ppd =} ppder (pp, m)
22 ## Compute the piecewise @var{m}-th derivative of a piecewise polynomial
23 ## struct @var{pp}. If @var{m} is omitted the first derivative is calculated.
24 ## @seealso{mkpp, ppval, ppint}
27 function ppd = ppder (pp, m)
29 if ((nargin < 1) || (nargin > 2))
35 if (! (isstruct (pp) && strcmp (pp.form, "pp")))
36 error ("ppder: PP must be a structure");
39 [x, p, n, k, d] = unmkpp (pp);
43 pd = zeros (prod (d), 1);
46 ff = bincoeff (f, m + 1) .* factorial (m + 1) ./ f;
48 pd = p(:,1:k) * diag (ff(1:k));
51 ppd = mkpp (x, pd, d);
55 %! x=0:8;y=[x.^2;x.^3+1];pp=spline(x,y);
57 %!assert(ppval(ppd,x),[2*x;3*x.^2],1e-14)
60 %!assert(ppval(ppd,x),[2*ones(size(x));6*x],1e-14)
64 %!assert(ppd.pieces,8)
65 %!assert(size(ppd.coefs),[16,1])
68 %!assert(ppd.pieces,1)
69 %!assert(size(ppd.coefs),[2,1])
70 %!assert(ppval(ppd,x),zeros(size(y)),1e-14)