]> Creatis software - CreaPhase.git/blob - octave_packages/m/polynomial/unmkpp.m
update packages
[CreaPhase.git] / octave_packages / m / polynomial / unmkpp.m
1 ## Copyright (C) 2000-2012 Paul Kienzle
2 ##
3 ## This file is part of Octave.
4 ##
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
9 ##
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 ## General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING.  If not, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {[@var{x}, @var{p}, @var{n}, @var{k}, @var{d}] =} unmkpp (@var{pp})
21 ##
22 ## Extract the components of a piecewise polynomial structure @var{pp}.
23 ## The components are:
24 ##
25 ## @table @asis
26 ## @item @var{x}
27 ## Sample points.
28 ##
29 ## @item @var{p}
30 ## Polynomial coefficients for points in sample interval.  @code{@var{p}
31 ## (@var{i}, :)} contains the coefficients for the polynomial over
32 ## interval @var{i} ordered from highest to lowest.  If @code{@var{d} >
33 ## 1}, @code{@var{p} (@var{r}, @var{i}, :)} contains the coefficients for
34 ## the r-th polynomial defined on interval @var{i}.
35 ##
36 ## @item @var{n}
37 ## Number of polynomial pieces.
38 ##
39 ## @item @var{k}
40 ## Order of the polynomial plus 1.
41 ##
42 ## @item @var{d}
43 ## Number of polynomials defined for each interval.
44 ## @end table
45 ##
46 ## @seealso{mkpp, ppval, spline, pchip}
47 ## @end deftypefn
48
49 function [x, P, n, k, d] = unmkpp (pp)
50
51   if (nargin != 1)
52     print_usage ();
53   endif
54   if (! (isstruct (pp) && isfield (pp, "form") && strcmp (pp.form, "pp")))
55     error ("unmkpp: PP must be a piecewise polynomial structure");
56   endif
57   x = pp.breaks;
58   P = pp.coefs;
59   n = pp.pieces;
60   k = pp.order;
61   d = pp.dim;
62
63 endfunction
64
65
66 %!test
67 %! b = 1:3;
68 %! c = 1:24;
69 %! pp = mkpp (b,c);
70 %! [x, P, n, k, d] = unmkpp (pp);
71 %! assert (x, b);
72 %! assert (P, reshape (c, [2 12]));
73 %! assert (n, 2);
74 %! assert (k, 12);
75 %! assert (d, 1);
76
77 %% Test input validation
78 %!error unmkpp ()
79 %!error unmkpp (1,2)
80 %!error <piecewise polynomial structure> unmkpp (1)
81 %!error <piecewise polynomial structure> unmkpp (struct ("field1", "pp"))
82 %!error <piecewise polynomial structure> unmkpp (struct ("form", "not_a_pp"))
83