annotate scripts/polynomial/unmkpp.m @ 20614:10ec79b47808

use new string_value method to handle value extraction errors * __voronoi__.cc, chol.cc, colamd.cc, fftw.cc: Use new string_value method.
author John W. Eaton <jwe@octave.org>
date Thu, 08 Oct 2015 18:15:56 -0400
parents aa36fb998a4d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
1 ## Copyright (C) 2000-2015 Paul Kienzle
5824
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
2 ##
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
4 ##
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
8 ## your option) any later version.
5824
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
9 ##
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
14 ##
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
17 ## <http://www.gnu.org/licenses/>.
5824
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
18
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
20 ## @deftypefn {Function File} {[@var{x}, @var{p}, @var{n}, @var{k}, @var{d}] =} unmkpp (@var{pp})
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
21 ##
11536
702dbd0c53f5 Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
22 ## Extract the components of a piecewise polynomial structure @var{pp}.
20200
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19867
diff changeset
23 ##
14104
614505385171 doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents: 13770
diff changeset
24 ## The components are:
5824
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
25 ##
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
26 ## @table @asis
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
27 ## @item @var{x}
8347
fa78cb8d8a5c corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents: 7017
diff changeset
28 ## Sample points.
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 9768
diff changeset
29 ##
5824
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
30 ## @item @var{p}
20200
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19867
diff changeset
31 ## Polynomial coefficients for points in sample interval.
20216
aa36fb998a4d maint: Remove unnecessary whitespace at end of lines.
Rik <rik@octave.org>
parents: 20200
diff changeset
32 ## @code{@var{p} (@var{i}, :)} contains the coefficients for the polynomial
20200
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19867
diff changeset
33 ## over interval @var{i} ordered from highest to lowest. If
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19867
diff changeset
34 ## @code{@var{d} > 1}, @code{@var{p} (@var{r}, @var{i}, :)} contains the
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19867
diff changeset
35 ## coefficients for the r-th polynomial defined on interval @var{i}.
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 9768
diff changeset
36 ##
5824
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
37 ## @item @var{n}
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
38 ## Number of polynomial pieces.
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 9768
diff changeset
39 ##
5824
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
40 ## @item @var{k}
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
41 ## Order of the polynomial plus 1.
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 9768
diff changeset
42 ##
5824
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
43 ## @item @var{d}
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
44 ## Number of polynomials defined for each interval.
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
45 ## @end table
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
46 ##
14104
614505385171 doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents: 13770
diff changeset
47 ## @seealso{mkpp, ppval, spline, pchip}
5824
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
48 ## @end deftypefn
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
49
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
50 function [x, P, n, k, d] = unmkpp (pp)
13770
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
51
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
52 if (nargin != 1)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5824
diff changeset
53 print_usage ();
5824
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
54 endif
13770
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
55 if (! (isstruct (pp) && isfield (pp, "form") && strcmp (pp.form, "pp")))
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
56 error ("unmkpp: PP must be a piecewise polynomial structure");
5824
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
57 endif
12608
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
58 x = pp.breaks;
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
59 P = pp.coefs;
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
60 n = pp.pieces;
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
61 k = pp.order;
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
62 d = pp.dim;
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
63
5824
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
64 endfunction
13770
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
65
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
66
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
67 %!test
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
68 %! b = 1:3;
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
69 %! c = 1:24;
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
70 %! pp = mkpp (b,c);
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
71 %! [x, P, n, k, d] = unmkpp (pp);
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
72 %! assert (x, b);
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
73 %! assert (P, reshape (c, [2 12]));
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
74 %! assert (n, 2);
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
75 %! assert (k, 12);
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
76 %! assert (d, 1);
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
77
19867
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
78 ## Test input validation
13770
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
79 %!error unmkpp ()
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
80 %!error unmkpp (1,2)
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
81 %!error <piecewise polynomial structure> unmkpp (1)
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
82 %!error <piecewise polynomial structure> unmkpp (struct ("field1", "pp"))
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
83 %!error <piecewise polynomial structure> unmkpp (struct ("form", "not_a_pp"))
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
84