annotate scripts/polynomial/unmkpp.m @ 14383:07c55bceca23 stable

Fix guarded_eval() subfunction in fminunc (bug #35534). * fminunc.m: Fix guarded_eval() subfunction in fminunc (bug #35534).
author Olaf Till <olaf.till@uni-jena.de>
date Wed, 15 Feb 2012 14:44:37 +0100
parents 72c96de7a403
children d63878346099
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 14104
diff changeset
1 ## Copyright (C) 2000-2012 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}.
14104
614505385171 doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents: 13770
diff changeset
23 ## The components are:
5824
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
24 ##
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
25 ## @table @asis
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
26 ## @item @var{x}
8347
fa78cb8d8a5c corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents: 7017
diff changeset
27 ## Sample points.
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 9768
diff changeset
28 ##
5824
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
29 ## @item @var{p}
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
30 ## Polynomial coefficients for points in sample interval. @code{@var{p}
5824
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
31 ## (@var{i}, :)} contains the coefficients for the polynomial over
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
32 ## interval @var{i} ordered from highest to lowest. If @code{@var{d} >
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
33 ## 1}, @code{@var{p} (@var{r}, @var{i}, :)} contains the coefficients for
9768
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 9245
diff changeset
34 ## 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
35 ##
5824
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
36 ## @item @var{n}
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
37 ## Number of polynomial pieces.
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 9768
diff changeset
38 ##
5824
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
39 ## @item @var{k}
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
40 ## Order of the polynomial plus 1.
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 9768
diff changeset
41 ##
5824
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
42 ## @item @var{d}
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
43 ## Number of polynomials defined for each interval.
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
44 ## @end table
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
45 ##
14104
614505385171 doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents: 13770
diff changeset
46 ## @seealso{mkpp, ppval, spline, pchip}
5824
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
47 ## @end deftypefn
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
48
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
49 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
50
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
51 if (nargin != 1)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5824
diff changeset
52 print_usage ();
5824
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
53 endif
13770
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
54 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
55 error ("unmkpp: PP must be a piecewise polynomial structure");
5824
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
56 endif
12608
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
57 x = pp.breaks;
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
58 P = pp.coefs;
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
59 n = pp.pieces;
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
60 k = pp.order;
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
61 d = pp.dim;
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 11587
diff changeset
62
5824
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
63 endfunction
13770
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
64
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 %!test
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
67 %! b = 1:3;
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
68 %! c = 1:24;
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
69 %! pp = mkpp (b,c);
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
70 %! [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
71 %! assert (x, b);
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
72 %! assert (P, reshape (c, [2 12]));
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
73 %! assert (n, 2);
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
74 %! assert (k, 12);
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
75 %! assert (d, 1);
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
76
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
77 %% Test input validation
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
78 %!error unmkpp ()
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
79 %!error unmkpp (1,2)
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
80 %!error <piecewise polynomial structure> unmkpp (1)
b0bb7bd9e0c8 unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
81 %!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
82 %!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
83